How can I use number_to_currency
and make it delete the zeros in the decimal part?
So if I have a number 30.50, I want to keep the .50, but if I have 30.00, I want to delete those zeros. I see the precision, but I don't know if I can use it conditionally to just be applied if the trailing decimals are zeros...
Thanks
num = 30.00
number_to_currency(num, :precision => (num.round == num) ? 0 : 2)
=> $30
num = 30.05
number_to_currency(num, :precision => (num.round == num) ? 0 : 2)
=> $30.05
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With