F
Filament14mo ago
Abi

format_money helper method returns incorrect value

Filament\Support\format_money(490, 'usd',100);

//returns $4.00 instead of $4.90
Filament\Support\format_money(490, 'usd',100);

//returns $4.00 instead of $4.90
4 Replies
ChesterS
ChesterS14mo ago
Hmm yeah it's because bcdiv doesn't have a scale set so it defaults to 0 (or whatever you have set). Not sure if this is a bug or intended @Abishek you can try using bcscale (https://www.php.net/manual/en/function.bcscale.php) to set it to 2 somewhere in your app Somewhere in the boot method or soemething. It should solve your issue
LeandroFerreira
LeandroFerreira14mo ago
vendor/filament/support/src/helpers.php
$money = bcdiv((string) $money, (string) $divideBy);

//should be
$money = bcdiv((string) $money, (string) $divideBy, $scale);
$money = bcdiv((string) $money, (string) $divideBy);

//should be
$money = bcdiv((string) $money, (string) $divideBy, $scale);
You could send a PR..
Abi
AbiOP14mo ago
Thank you. Looking into it now
Abi
AbiOP14mo ago
GitHub
add scale to bcdiv to fix format_money method to include decimal va...
Fixes the format_money helper to use 2 decimal points when dividing with the current implementation Filament\Support\format_money(490, 'usd',100); //returns $4.00 instead of $4.90 with th...
Want results from more Discord servers?
Add your server