# Precision problem in float data type

**URL:** <https://www.ruby-forum.com/t/precision-problem-in-float-data-type/104680>\
**Category:** Rails\
**Created:** [May 21, 2007, 1:58pm UTC](https://www.ruby-forum.com/t/precision-problem-in-float-data-type/104680 "2007-05-21T13:58:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/13edae/32.png) [@ruby](https://www.ruby-forum.com/u/ruby)\
**Post date:** [May 21, 2007, 1:58pm UTC](https://www.ruby-forum.com/t/precision-problem-in-float-data-type/104680/1 "2007-05-21T13:58:13Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/13edae/32.png) [@ruby](https://www.ruby-forum.com/u/ruby)\
**Post date:** [May 21, 2007, 3:14pm UTC](https://www.ruby-forum.com/t/precision-problem-in-float-data-type/104680/2 "2007-05-21T15:14:58Z")

</div>

On May 21, 2007, at 7:58 AM, ruby wrote:

> ```
> 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 B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
