oj: Oj rounding inconsistency

irb(main):055:0> Oj.dump(81.9)
=> "81.90000000000001"
irb(main):056:0> Oj.dump(81.8)
=> "81.8"
irb(main):057:0> Oj.dump(81.7)
=> "81.7"
irb(main):058:0> Oj.dump(81.6)
=> "81.59999999999999"
irb(main):059:0> Oj.dump(81.5)
=> "81.5"
irb(main):060:0> Oj.dump(81.4)
=> "81.40000000000001"
irb(main):061:0> Oj.dump(81.3)
=> "81.3"
irb(main):062:0> Oj.dump(81.2)
=> "81.2"
irb(main):063:0> Oj.dump(81.1)
=> "81.09999999999999"
irb(main):064:0> Oj.dump(81.0)
=> "81.0"
irb(main):065:0> Oj.dump(80.9)
=> "80.90000000000001"
irb(main):066:0> Oj.dump(80.8)
=> "80.8"
irb(main):067:0>

This is using the latest version of Oj - is there any reason Oj does this? I could only find a very old issue regarding a similar regarding extra decimals being added and it seemed like more of a Rails configuration issue.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 25 (12 by maintainers)

Most upvoted comments

Have to support my users. 😄

wab is fine. It is intended to be the fastest of the bunch and not care about cosmetics such as precision when it is outside the range of what is supported by the IEEE standard. Precisions above 15 decimals is not guaranteed so wab doesn’t bother with the rounding since the default is 15 places and not 16.

I’m not sure why that is happening strict mode but will look into it. I know dropping into the rails mode does make some global changes.