moneyphp / money

PHP implementation of Fowler's Money pattern.
http://moneyphp.org
MIT License
4.6k stars 440 forks source link

Simple rounding test failed #677

Closed palansher closed 2 years ago

palansher commented 2 years ago

Hello!

I am trying to check the corrections of rounding. This simple test must be passed:

1/7/13*7*13 = 1

But result discourages:

use Money\Money;

$eur1 = Money::EUR(100);
$result= $eur1->divide(7)->divide(13)->multiply(7)->multiply(13);
echo $result->getAmount().PHP_EOL;

the result is 91 instead of 100 But even Windows 10 calculator app provides the correct answer =1.

also PHP:

<?php
echo 1/7/13*7*13;
// =1

How can I get the correct answer (=1)?

thank you for your work!

frederikbosch commented 2 years ago

The answer 91 is correct. multiply and divide lose their decimal points, see the second argument you can pass for the rounding modes.