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.
ruby (Guest)
on 2007-05-21 15: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
Rob B. (Guest)
on 2007-05-21 17: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 B.
This topic is locked and can not be replied to.