Forum: Ruby on Rails precision problem in float data type

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Cf3efadeb0461f30a12039185319a2dc?d=identicon&s=25 ruby (Guest)
on 2007-05-21 13:58
Hi there,

  I have been facing problem in displaying the value of the column which
is of type float. by default it displays only single digit after decimal
point so how can I set the precision while displaying the value of the
field in the rhtml file

    thanking you
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2007-05-21 15:14
(Received via mailing list)
On May 21, 2007, at 7:58 AM, ruby wrote:

>     thanking you
You need to format it yourself as in:

<%= '%.2f' % [your_value] %>

 >> '%.2f' % [4.5]
=> "4.50"
 >> 4.5.to_s
=> "4.5"


Rob Biedenharn
This topic is locked and can not be replied to.