fix rounding from string

This commit is contained in:
Sergey Yastrebov 2018-04-20 13:19:35 +03:00
parent b97a4ae031
commit f94b7aadd3
3 changed files with 18 additions and 0 deletions

View File

@ -78,6 +78,16 @@ class MoneyToLocalizedStringTransformerTest extends TestCase
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
IntlTestHelper::requireFullIntl($this, false);
\Locale::setDefault('de_AT');
$this->assertSame(3655, (int) $transformer->reverseTransform('36,55'));
}
public function testFloatToIntConversionMismatchOnTransform()
{
$transformer = new MoneyToLocalizedStringTransformer(null, null, MoneyToLocalizedStringTransformer::ROUND_DOWN, 100);
IntlTestHelper::requireFullIntl($this, false);
\Locale::setDefault('de_AT');
$this->assertSame('10,20', $transformer->transform(1020));
}
}

View File

@ -708,6 +708,7 @@ class NumberFormatter
} elseif (isset(self::$customRoundingList[$roundingModeAttribute])) {
$roundingCoef = pow(10, $precision);
$value *= $roundingCoef;
$value = (float) (string) $value;
switch ($roundingModeAttribute) {
case self::ROUND_CEILING:

View File

@ -428,6 +428,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
// array(1.125, '1.13'),
array(1.127, '1.13'),
array(1.129, '1.13'),
array(1020 / 100, '10.20'),
);
}
@ -451,6 +452,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
array(1.125, '1.12'),
array(1.127, '1.13'),
array(1.129, '1.13'),
array(1020 / 100, '10.20'),
);
}
@ -474,6 +476,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
array(1.125, '1.12'),
array(1.127, '1.13'),
array(1.129, '1.13'),
array(1020 / 100, '10.20'),
);
}
@ -498,6 +501,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
array(-1.123, '-1.12'),
array(-1.125, '-1.12'),
array(-1.127, '-1.12'),
array(1020 / 100, '10.20'),
);
}
@ -522,6 +526,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
array(-1.123, '-1.13'),
array(-1.125, '-1.13'),
array(-1.127, '-1.13'),
array(1020 / 100, '10.20'),
);
}
@ -546,6 +551,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
array(-1.123, '-1.12'),
array(-1.125, '-1.12'),
array(-1.127, '-1.12'),
array(1020 / 100, '10.20'),
);
}
@ -570,6 +576,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
array(-1.123, '-1.13'),
array(-1.125, '-1.13'),
array(-1.127, '-1.13'),
array(1020 / 100, '10.20'),
);
}