[ ] Make all display with brick/money and w/ custom currency
Store with 8 digits
Calculate with 8 digits
But round to 2 digits
It will be invisible to the user if all rounded numbers are the same for a transaction or whatever, but in DB base one user will receive 0.00000001 more cts
Instead of 0.01 more cts, this case is more plainfull for others
After some tests, take this code to handle YC currency :
$youlCoinCurrency = new Currency(
'YLC', // currency code
0, // numeric currency code, useful when storing monies in a database; set to 0 if unused
'YoulCoin', // currency name
8 // default scale
);
$formatter = new \NumberFormatter('en_US', \NumberFormatter::CURRENCY);
$formatter->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, "\xC2\xA5\xC2\xA2");
$formatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 2);
$money = Money::of('10', $youlCoinCurrency);
dump((string)$money->getMinorAmount()->toInt());
$arrayMoney = $money->split(3);
foreach ($arrayMoney as $money){
dump($string = (string)$money->getMinorAmount()->toInt());
dump(Money::ofMinor($string, $youlCoinCurrency)->formatWith($formatter));
dump('-------------------------');
}
dd('ok');
https://github.com/brick/money
Store with 8 digits
Calculate with 8 digits
But round to 2 digits
It will be invisible to the user if all rounded numbers are the same for a transaction or whatever, but in DB base one user will receive 0.00000001 more cts
Instead of 0.01 more cts, this case is more plainfull for others
After some tests, take this code to handle YC currency :