moneyphp / money

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

FixedExchange currency conversion problem with ROUND_UP #728

Closed tashik closed 1 year ago

tashik commented 1 year ago
$exchange = new FixedExchange([
      'USD' => [
              'KZT' => "374.3",
       ]   
]);
$converter = new Converter(new ISOCurrencies(), $exchange);
$amount = $converter->convert(new Money(800, new Currency('USD')), new Currency('KZT'), Money::ROUND_UP);
print($amount->getAmount());

299441 instead of 29940. As you can see, I pass a string "374.3" when creating and exchange instance, but in your code (CurrencyPair __construct) you convert my correct string to incorrect float. Then in convert method of Converter class you try to get a string from that float - and fail to get correct string. The problem is that currency conversion ratio before multiplying becomes 374.3000000001. Please, advise, why so and how to fix this?

We use php/money 3.x since our project is PHP 7.2.4

frederikbosch commented 1 year ago

We only support versions supported by PHP, hence no support for PHP 7.2.