moneyphp / money

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

Is it possibly to specify a currency to more decimals? #696

Closed devsi closed 1 year ago

devsi commented 2 years ago

For example I want to see CAD to 8 decimal places, and calculate at that precision too. Is this possible with moneyphp?

magikid commented 2 years ago

At the moment, no, it is not possible in an easily configurable way. I am currently adding more decimal places to the USD currency by modifying the currency.php file in the composer post-install and post-update scripts.

<?php

$currenciesFilePath = __DIR__ . '/../vendor/moneyphp/money/resources/currency.php';
$currencies = include $currenciesFilePath;
$currencies['USD']['minorUnit'] = 5;

file_put_contents($currenciesFilePath, sprintf('<?php return %s;', var_export($currencies, true)));

Would a PR making the minor unit of currencies configurable be accepted by this project?

arokettu commented 1 year ago

@devsi You can use a custom implementation of a Currencies interface instead of ISOCurrencies

frederikbosch commented 1 year ago

Question is answered.