Certain floating point numbers have inherent inaccuracy from binary floating point representation:
> puts "%.50f" % (0.5) # cleanly representable
> puts "%.50f" % (0.1) # not cleanly representable
> puts "%.50f" % ("0.1".to_d)
> puts "%.50f" % ("0.1".to_d * "10".to_d)
%.50f specifier takes a floating point value, so that decimal value needs to be converted to floating point before it's rendered for display, and as such is subjected to the same floating point noise you get in ordinary floating point values.
sprintf and friends, like the
String#% method, do conversions automatically depending on the type specified in the placeholder.
To suppress that you'd have to use the
.to_s method on the BigDecimal number directly. It can take an optional format specifier if you want a certain number of places, and this can be chained in to a
%s placeholder in your other string.