Browse Source

Fixed regression in formatter when passed value is a string representation of float without decimals

tags/2.0.16
SilverFire - Dmitry Naumenko 6 years ago
parent
commit
a03376413c
No known key found for this signature in database
GPG Key ID: 39DD917A92B270A
  1. 5
      framework/i18n/Formatter.php
  2. 5
      tests/framework/i18n/FormatterNumberTest.php

5
framework/i18n/Formatter.php

@ -1794,7 +1794,10 @@ class Formatter extends Component
$value = 0;
}
return (string) $normalizedValue !== (string) $value;
return !(
(string) $normalizedValue === (string) $value
|| (string) $normalizedValue === (string)((int) $value)
);
}
/**

5
tests/framework/i18n/FormatterNumberTest.php

@ -92,6 +92,7 @@ class FormatterNumberTest extends TestCase
public function testAsInteger()
{
$this->assertSame('123', $this->formatter->asInteger(123));
$this->assertSame('123', $this->formatter->asInteger(123.00));
$this->assertSame('123', $this->formatter->asInteger(123.23));
$this->assertSame('123', $this->formatter->asInteger(123.53));
$this->assertSame('0', $this->formatter->asInteger(0));
@ -267,6 +268,7 @@ class FormatterNumberTest extends TestCase
{
$this->assertSame('12,300%', $this->formatter->asPercent(123));
$this->assertSame('12,300%', $this->formatter->asPercent('123'));
$this->assertSame('12,300%', $this->formatter->asPercent('123.0'));
$this->assertSame('12%', $this->formatter->asPercent(0.1234));
$this->assertSame('12%', $this->formatter->asPercent('0.1234'));
$this->assertSame('-1%', $this->formatter->asPercent(-0.009343));
@ -293,6 +295,7 @@ class FormatterNumberTest extends TestCase
{
$this->formatter->locale = 'en-US';
$this->assertSame('$123.00', $this->formatter->asCurrency('123'));
$this->assertSame('$123.00', $this->formatter->asCurrency('123.00'));
$this->assertSame('$123,456.00', $this->formatter->asCurrency('123456'));
$this->assertSame('$0.00', $this->formatter->asCurrency('0'));
@ -410,6 +413,7 @@ class FormatterNumberTest extends TestCase
$this->formatter->locale = 'de-DE';
$this->formatter->currencyCode = null;
$this->assertSame("123\xc2\xa0€", $this->formatter->asCurrency('123'));
$this->assertSame("123\xc2\xa0€", $this->formatter->asCurrency('123.00'));
$this->assertSame("123\xc2\xa0€", $this->formatter->asCurrency('123', 'EUR'));
$this->formatter->currencyCode = 'USD';
$this->assertSame("123\xc2\xa0$", $this->formatter->asCurrency('123'));
@ -453,6 +457,7 @@ class FormatterNumberTest extends TestCase
{
$this->formatter->currencyCode = 'USD';
$this->assertSame('USD 123.00', $this->formatter->asCurrency('123'));
$this->assertSame('USD 123.00', $this->formatter->asCurrency('123.00'));
$this->assertSame('USD 0.00', $this->formatter->asCurrency('0'));
$this->assertSame('USD -123.45', $this->formatter->asCurrency('-123.45'));
$this->assertSame('USD -123.45', $this->formatter->asCurrency(-123.45));

Loading…
Cancel
Save