bug #26781 [Form] Fix precision of MoneyToLocalizedStringTransformer's divisions on transform() (syastrebov)
This PR was merged into the 2.7 branch.
Discussion
----------
[Form] Fix precision of MoneyToLocalizedStringTransformer's divisions on transform()
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | no
| License | MIT
| Doc PR |
Related issue https://github.com/symfony/symfony/issues/21026.
Previous PR https://github.com/symfony/symfony/pull/24036.
Similar fix for `transform()` method.
Commits
-------
f94b7aadd3
fix rounding from string
This commit is contained in:
commit
05d69bb739
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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'),
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user