mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 13:58:55 +08:00
Fixed regression in formatter when passed value is a string representation of float without decimals
This commit is contained in:
@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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));
|
||||
|
||||
Reference in New Issue
Block a user