# Re: How to format decimals on the fly (for EOF blocks)?

**URL:** <https://www.ruby-forum.com/t/re-how-to-format-decimals-on-the-fly-for-eof-blocks/147105>\
**Category:** Ruby\
**Created:** [August 28, 2008, 2:16pm UTC](https://www.ruby-forum.com/t/re-how-to-format-decimals-on-the-fly-for-eof-blocks/147105 "2008-08-28T14:16:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stickstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@stickstone](https://www.ruby-forum.com/u/stickstone)\
**Post date:** [August 28, 2008, 2:16pm UTC](https://www.ruby-forum.com/t/re-how-to-format-decimals-on-the-fly-for-eof-blocks/147105/1 "2008-08-28T14:16:18Z")

</div>

I don’t understand how your figures relate to each other in the example  
you  
gave, but here are a few ways to format a float to one decimal place:

val = 0.4423

printf “%6.1f mcg\n”, val

str = sprintf("%6.1f mcg", val)  
puts str

str = “%6.1f mcg” % val  
puts str

For more info: ri Kernel#sprintf, ri String#%
