I have a BigDecimal that has either 0, 1 or 2 decimal digits (I’m calling round(2) on it). I want to display it in a view in such a way that it’ll only show as many decimal digits as needed. In other words:
7.0 -> "7"
7.5 -> "7.5"
7.67 -> "7.67"
How do I achieve this? So far, it’s showing “7.0” instead of “7”.
For your views, look at the methods from the NumberHelper, in particular the
number_with_precision, http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#method-i-number_with_precisionParticularly, you want the strip_insignificant_zeros option.