# precision problem in float data type

**URL:** <https://discuss.rubyonrails.org/t/precision-problem-in-float-data-type/13220>\
**Category:** rubyonrails-talk\
**Created:** [May 21, 2007, 1:13pm UTC](https://discuss.rubyonrails.org/t/precision-problem-in-float-data-type/13220 "2007-05-21T13:13:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rab](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/rab/32/710_2.png) [@rab](https://discuss.rubyonrails.org/u/rab)\
**Post date:** [May 21, 2007, 1:13pm UTC](https://discuss.rubyonrails.org/t/precision-problem-in-float-data-type/13220/1 "2007-05-21T13:13:21Z")

</div>

> Hi there,
> 
> &nbsp;&nbsp;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
> 
> &nbsp;&nbsp;&nbsp;&nbsp;thanking you

You need to format it yourself as in:

\<%= '%.2f' % [your\_value] %\>

Compare: \>\> '%.2f' % [4.5] =\> "4.50" \>\> 4.5.to\_s =\> "4.5"

-Rob

Rob Biedenharn [http://agileconsultingllc.com](http://agileconsultingllc.com) Rob@AgileConsultingLLC.com
