Reputation: 11892
With Ruby 2.3.7,
'%.2g' % 1.05
returns "1.1"
But with Ruby 2.4.0
'%.2g' % 1.05
returns "1.0"
Why is this behaviour different? Thanks
Upvotes: 0
Views: 31
Reputation: 106982
In Ruby 2.4 the default strategy of Float#round
was changed to Gaussian rounding.
Upvotes: 2
Reputation: 11892
"This was an early effort by Nobu to handle cases where floating point numbers rounded inconsistently with Kernel#sprintf in ruby-2.3.3"
https://blog.heroku.com/ruby-2-4-features-hashes-integers-rounding#actual-rounding-changes
Upvotes: 0