I 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) %>

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • blogmarks
  • Book.mark.hu
  • co.mments
  • Technorati
  • YahooMyWeb
  • IndianPad
  • DZone