8000 fix rounding from string · symfony/symfony@f94b7aa · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f94b7aa

Browse files
committed
fix rounding from string
1 parent b97a4ae commit f94b7aa

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ public function testFloatToIntConversionMismatchOnReversTransform()
7878
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
7979
IntlTestHelper::requireFullIntl($this, false);
8080
\Locale::setDefault('de_AT');
81+
8182
$this->assertSame(3655, (int) $transformer->reverseTransform('36,55'));
8283
}
84+
85+
public function testFloatToIntConversionMismatchOnTransform()
86+
{
87+
$transformer = new MoneyToLocalizedStringTransformer(null, null, MoneyToLocalizedStringTransformer::ROUND_DOWN, 100);
88+
IntlTestHelper::requireFullIntl($this, false);
89+
\Locale::setDefault('de_AT');
90+
91+
$this->assertSame('10,20', $transformer->transform(1020));
92+
}
8393
}

src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ private function round($value, $precision)
708708
} elseif (isset(self::$customRoundingList[$roundingModeAttribute])) {
709709
$roundingCoef = pow(10, $precision);
710710
$value *= $roundingCoef;
711+
$value = (float) (string) $value;
711712

712713
switch ($roundingModeAttribute) {
713714
case self::ROUND_CEILING:

src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ public function formatRoundingModeRoundHalfUpProvider()
428428
// array(1.125, '1.13'),
429429
array(1.127, '1.13'),
430430
array(1.129, '1.13'),
431+
array(1020 / 100, '10.20'),
431432
);
432433
}
433434

@@ -451,6 +452,7 @@ public function formatRoundingModeRoundHalfDownProvider()
451452
array(1.125, '1.12'),
452453
array(1.127, '1.13'),
453454
array(1.129, '1.13'),
455+
array(1020 / 100, '10.20'),
454456
);
455457
}
456458

@@ -474,6 +476,7 @@ public function formatRoundingModeRoundHalfEvenProvider()
474476
array(1.125, '1.12'),
475477
array(1.127, '1.13'),
476478
array(1.129, '1.13'),
479+
array(1020 / 100, '10.20'),
477480
);
478481
}
479482

@@ -498,6 +501,7 @@ public function formatRoundingModeRoundCeilingProvider()
498501
array(-1.123, '-1.12'),
499502
array(-1.125, '-1.12'),
500503
array(-1.127, '-1.12'),
504+
array(1020 / 100, '10.20'),
501505
);
502506
}
503507

@@ -522,6 +526,7 @@ public function formatRoundingModeRoundFloorProvider()
522526
array(-1.123, '-1.13'),
523527
array(-1.125, '-1.13'),
524528
array(-1.127, '-1.13'),
529+
array(1020 / 100, '10.20'),
525530
);
526531
}
527532

@@ -546,6 +551,7 @@ public function formatRoundingModeRoundDownProvider()
546551
array(-1.123, '-1.12'),
547552
array(-1.125, '-1.12'),
548553
array(-1.127, '-1.12'),
554+
array(1020 / 100, '10.20'),
549555
);
550556
}
551557

@@ -570,6 +576,7 @@ public function formatRoundingModeRoundUpProvider()
570576
array(-1.123, '-1.13'),
571577
array(-1.125, '-1.13'),
572578
array(-1.127, '-1.13'),
579+
array(1020 / 100, '10.20'),
573580
);
574581
}
575582

0 commit comments

Comments
 (0)
0