Fixing the precision for floating points numbers in Ruby
Ruby December 17th, 2007I really came across this beautiful function which allows you to set the precison for a floating point numbers.
The situation was somewhat like this, I wanted the floating point numbers like 1.5 to be displayed as 1.50 i.e upto 2 decimal places fixed after the point.
So , my dear Ruby provides a beautiful function termed as number_with_precision which allows you set the number of digits after the decimal point.
The following is the way of how u can use it:Here I am setting the floating point numbers upto 2 decimal places
<%= number_with_precision(floating_point_number,2) %>








