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

This commit is contained in:
SilverFire - Dmitry Naumenko
2018-12-03 18:22:11 +02:00
parent 8bccbd595d
commit a03376413c
2 changed files with 9 additions and 1 deletions

View File

@ -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)
);
}
/**

View File

@ -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));