Skip to content

Commit 65e0b29

Browse files
committed
fix rounding from string
1 parent 6e80476 commit 65e0b29

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,12 @@ public function testFloatToIntConversionMismatchOnReversTransform()
8080
\Locale::setDefault('de_AT');
8181
$this->assertSame(3655, (int) $transformer->reverseTransform('36,55'));
8282
}
83+
84+
public function testFloatToIntConversionMismatchOnTransform()
85+
{
86+
$transformer = new MoneyToLocalizedStringTransformer(null, null, MoneyToLocalizedStringTransformer::ROUND_DOWN, 100);
87+
IntlTestHelper::requireFullIntl($this, false);
88+
\Locale::setDefault('de_AT');
89+
$this->assertSame('10,20', $transformer->transform('1020'));
90+
}
8391
}

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

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

714715
switch ($roundingModeAttribute) {
715716
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy