From a03376413c133d51665bc65f18280aae05c18dc5 Mon Sep 17 00:00:00 2001 From: SilverFire - Dmitry Naumenko Date: Mon, 3 Dec 2018 18:22:11 +0200 Subject: [PATCH] Fixed regression in formatter when passed value is a string representation of float without decimals --- framework/i18n/Formatter.php | 5 ++++- tests/framework/i18n/FormatterNumberTest.php | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/framework/i18n/Formatter.php b/framework/i18n/Formatter.php index 79b59d7ea0..b2b2615865 100644 --- a/framework/i18n/Formatter.php +++ b/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) + ); } /** diff --git a/tests/framework/i18n/FormatterNumberTest.php b/tests/framework/i18n/FormatterNumberTest.php index 12cc5d60b9..6b60de1f68 100644 --- a/tests/framework/i18n/FormatterNumberTest.php +++ b/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));