Skip to content

Commit

Permalink
Merge pull request #91 from b1rdex/fix-floats
Browse files Browse the repository at this point in the history
Fix floats
  • Loading branch information
wapmorgan committed Aug 3, 2020
2 parents 2976835 + 059c66a commit 5a8b5b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Russian/MoneySpeller.php
Expand Up @@ -45,7 +45,9 @@ public static function spell(
$currency = static::canonizeCurrency($currency);

$integer = floor($value);
$fractional = floor(($value * 100) % 100);
$fractional = fmod($value, $integer);
$fractional = round($fractional, 2);
$fractional *= 100;

switch ($format) {
case static::SHORT_FORMAT:
Expand Down
6 changes: 6 additions & 0 deletions tests/Russian/MoneySpellerTest.php
Expand Up @@ -48,6 +48,12 @@ public function moneyAmountsProvider()
[123, Currency::PESO, MoneySpeller::SHORT_FORMAT, '123 песо'],
[123, Currency::FRANC, MoneySpeller::SHORT_FORMAT, '123 франка'],
[123, Currency::LIRA, MoneySpeller::SHORT_FORMAT, '123 лиры'],
[256.4, Currency::RUBLE, MoneySpeller::SHORT_FORMAT, '256 рублей 40 копеек'],
[65536.4, Currency::RUBLE, MoneySpeller::SHORT_FORMAT, '65536 рублей 40 копеек'],
[16777216.4, Currency::RUBLE, MoneySpeller::SHORT_FORMAT, '16777216 рублей 40 копеек'],
[4294967296.4, Currency::RUBLE, MoneySpeller::SHORT_FORMAT, '4294967296 рублей 40 копеек'],
[4294967297.4, Currency::RUBLE, MoneySpeller::SHORT_FORMAT, '4294967297 рублей 40 копеек'],
[4294967296.4, Currency::RUBLE, MoneySpeller::DUPLICATION_FORMAT, 'четыре миллиарда двести девяносто четыре миллиона девятьсот шестьдесят семь тысяч двести девяносто шесть (4294967296) рублей сорок (40) копеек'],
];
}

Expand Down

0 comments on commit 5a8b5b0

Please sign in to comment.