I have a float price:
number_to_currency(m.price, :locale => 'en_us')
I get: $39.00
How can I remove .00
, I want get:
$39
You can set the precision to 0 as documented here in the Rails API Docs.
number_to_currency(m.price, locale: :en, precision: 0)
Be aware that your prices will be rounded, anything from $38.50 to $39.49 will be displayed as $39.
Edit: Exchanged locale :en_us
for :en
, which might be enabled in more apps.
Assuming that you want to skip decimals only in case of 0 cents, how about
number_to_currency(m.price, :locale => 'en_us').gsub(/\.00$/, "")
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