Difference in sprintf float rounding
irb(main):006:0> sprintf "%0.01f", 5.55
irb(main):001:0> sprintf "%0.01f", 5.55
Is the change intentional? If yes, what prompted this rounding change?
This is currently causing issues on iso8601 serializer on Rails https://github.com/rails/rails/blob/04c512da1247a54474cfd8bef17a9e9019c34004/activesupport/lib/active_support/duration/iso8601_serializer.rb#L25
Updated by vipulnsward (Vipul Amler) over 5 years ago
Nobuyoshi Nakada wrote:
Resulting 5.6 by rounding 5.55 off to one decimal place looks more "natural", than 5.5.
New behavior considers binary representation error.
What problem occurs concretely?
hmm, even C does it this way - http://codepad.org/raENqNSj
No, problem per-se, I was not sure of why this change was, or where it was "fixed". Will fix on Rails End to take this into account.