# How to force a decimal

**URL:** <https://www.ruby-forum.com/t/how-to-force-a-decimal/141014>\
**Category:** Ruby\
**Created:** [June 20, 2008, 8:13pm UTC](https://www.ruby-forum.com/t/how-to-force-a-decimal/141014 "2008-06-20T20:13:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [June 20, 2008, 8:13pm UTC](https://www.ruby-forum.com/t/how-to-force-a-decimal/141014/1 "2008-06-20T20:13:19Z")

</div>

Hey there all,

This should be simple. I need to know how to force a decimal place.

say i wanted to do 3.5.to\_s  
but i need that to be 3.50 as the string,

how would i do this?

thanks

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [June 20, 2008, 8:40pm UTC](https://www.ruby-forum.com/t/how-to-force-a-decimal/141014/2 "2008-06-20T20:40:55Z")

</div>

> say i wanted to do 3.5.to\_s  
> but i need that to be 3.50 as the string,

Use String#% and friends:

“%.2f” % 3.5

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [June 20, 2008, 9:19pm UTC](https://www.ruby-forum.com/t/how-to-force-a-decimal/141014/3 "2008-06-20T21:19:10Z")

</div>

cool, thanks much !
