Hey I am using the ruby on rails framework and I have a price variable that is a decimal. Naturally values like $39.99 is fine but when the price is $39.90 my app shows the price as $39.9 How could I change that.
My view
%b price
= @product.price
rails includes the number_to_currency(@product.price)
helper. Little simpler and easier to remember.
The standard answer here is to use sprintf.
sprintf("$%2.2f", @product.price)
This will format your number with a leading dollar sign, then the number to two decimal places.
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