# How to format floating point number

**URL:** <https://www.ruby-forum.com/t/how-to-format-floating-point-number/68269>\
**Category:** Rails\
**Created:** [September 11, 2006, 11:05am UTC](https://www.ruby-forum.com/t/how-to-format-floating-point-number/68269 "2006-09-11T11:05:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kspt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e9c0ed/32.png) [@kspt](https://www.ruby-forum.com/u/kspt)\
**Post date:** [September 11, 2006, 11:05am UTC](https://www.ruby-forum.com/t/how-to-format-floating-point-number/68269/1 "2006-09-11T11:05:58Z")

</div>

hello  
i need to format the retrieved value to two decimal points in ruby. MY  
problem is: if the value is 15.0 i need to print it as 15.00 and if it  
is 12.5 it should be 12.50. please help me in this.

---

<div class="post-metadata">

**Author:** ![kspt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e9c0ed/32.png) [@kspt](https://www.ruby-forum.com/u/kspt)\
**Post date:** [September 11, 2006, 11:43am UTC](https://www.ruby-forum.com/t/how-to-format-floating-point-number/68269/2 "2006-09-11T11:43:49Z")

</div>

In Ruby or Rails? If you are using rails, it comes with a nice helper  
method  
called number\_to\_currency.

Use it like so,

number\_to\_currency(15.0) or number\_to\_currency(variable\_name)

Hope that helps,  
Tyler P.

---

<div class="post-metadata">

**Author:** ![kspt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e9c0ed/32.png) [@kspt](https://www.ruby-forum.com/u/kspt)\
**Post date:** [September 11, 2006, 11:45am UTC](https://www.ruby-forum.com/t/how-to-format-floating-point-number/68269/3 "2006-09-11T11:45:49Z")

</div>

‘%.2f’ % 12.5 =\> “12.50”

Am 11.09.2006 um 11:05 schrieb Ks Ben:

> hello  
> i need to format the retrieved value to two decimal points in ruby. MY  
> problem is: if the value is 15.0 i need to print it as 15.00 and if it  
> is 12.5 it should be 12.50. please help me in this.
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Thomas F.  
wollzelle

> **[Pioneering Digital Strategy, Design & Technology Since 2000](https://www.wollzelle.com/)**
>
> Create.Transform.Succeed. We leverage the impact of design to transform products, teams, and organisations. → Email us about your challenge About Us At Wollzelle,...

questentier on AIM  
madrobby on [irc.freenode.net](http://irc.freenode.net)

[http://www.fluxiom.com](http://www.fluxiom.com) :: online digital asset management  
[http://script.aculo.us](http://script.aculo.us) :: Web 2.0 JavaScript  
[http://mir.aculo.us](http://mir.aculo.us) :: Where no web developer has gone before
