I have a dynamically generated table that multiplies price * qty. Some of the prices are in partial cents. For example
if the price of an item is 0.0375 I can display that in my table as
number_to_currency(0.0375,:precision => 4)
=> $0.0375
but on quantities where the price is a standard 2 decimal number I get
number_to_currency(33.95,:precision => 4)
=> $39.9500
I need a way to trim the trailing zeroes of a decimal value. Keep in mind that the output is in a Model.each block so I'm uncertain I can modify the precision parameter conditionally.
Try to specify strip_insignificant_zeros
option:
number_to_currency(33.95, precision: 4, strip_insignificant_zeros: true)
It should remove zeros after decimal separator. Here is description of this option.
The default for this method is 2. So you simply need
number_to_currency(33.95)
http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#method-i-number_to_currency
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