If it's a :float
or :decimal
, 80
and 80.00
in Ruby are going to be the same thing (as will 80.0000
). The latter isn't "stored" with more decimal places, and trailing zeroes only make sense in the view. You can use sprintf
like you said, or you can use Rails' handy number_with_precision
helper:
<%= number_with_precision price, :precision => 2 %>
Here's another SO question on this topic, by the way. @Matthew Rudy is right about one thing: For money columns you should be using :decimal
.
If you're really committed to not having this in your view, you could use something like Draper to apply decorators to your attributes (which will merely move your number_with_precision
call out of the way and into a new Decorator class), but it's probably overkill in this instance.