sprintf("%g", [float]) allows me to format a floating point number without specifying precision, such that 10.00 is rendered as 10 and 10.01 is rendered as 10.01, and so on. This is neat.
In my application I’m rendering numbers using the Rails NumberHelper methods so that I can take advantage of the localization features, but I can’t figure out how to achieve the above functionality through these helpers since they expect an explicit :precision option.
Is there a simple way around this?
I have solved this by adding another method to the
NumberHelpermodule as follows:It is the specific call to
number_with_delimiterwith the%goption which renders the number as described in the code comments above.This works great for me, but I’d welcome thoughts on this solution.