Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Strange dump behavior for floats #78

austinthecoder opened this Issue · 5 comments

2 participants


Whenever the value is a specific float, it gets changed. Here's some examples:

> Oj.dump({'a' => 70.35})
=> "{\"a\":70.34999999999999}"

> Oj.dump({'a' => 60.35})
=> "{\"a\":60.35}"

You will probably find that Ruby does something similar when printing. Floats are inherently imprecise. Others have noticed this and use BigDecimals instead when precision is important. There is an option in Oj to force the use of BigDecimal when loading. It is :big decimal_load.

Does that answer the question?


Thanks for the response. I understand that Floats are imprecise, but I would expect that since 70.35.to_s is "70.35" then Oj.dump(70.35) would be the same. Does it not make sense for Oj.dump to just call to_s on the object? Is this because it's done in C?


Changed the number of decimals to 15 instead of 16 and that seems to fix the problem. It will be in the next release.


Excellent! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.