What is the ruby expression "%.1f" and how does this round a decimal?
decimal, floating-point, rounding, ruby
Solution
It's the format string used by `Kernel#sprintf`.
The syntax of a format string is:
%[flags][width][.precision]type
`%.2f` means to use the floating-point format with 2 digits of precision.
Problem
I want to round a float with many decimal places, such as `2.638232371` down to one decimal place, such as `2.6`. I found this will do so: ``` "%.2f" % 1.93213 #=> 1.93 ``` But what is "%.2f"? and is the result a string? I'd just like to understand how this works.