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

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#%

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs