Interesting point. I’m not sure whether this is a bug or just
unspecified behaviour: While class Float defines a method ‘round’, the
documentation for sprintf does NOT say that this method is used for
formatting. Interestingly, it does not say anything about rounding.
The reason for the fact that 12.5 is rounded down, but 13.5 is rounded
up, could perhaps be that 0.135 can’t be represented exactly as a
floating point mantissa, while 0.125 can.
I suggest that you open an issue on the Ruby bugtracker, but not as a
bug against the implementation of sprintf, but against the documentation
which does not explain the effect of rounding. You can provide your case
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.