ohler55 / oj

Optimized JSON
http://www.ohler.com/oj
MIT License
3.12k stars 250 forks source link

How to avoid outputting small floats in scientific notation #893

Closed bryanp closed 10 months ago

bryanp commented 11 months ago

Small floats are dumped in scientific notation:

irb(main):002:0> Oj.dump(0.0000000001)
=> "1e-10"

I don't see an option to prevent this. Curious if there's a way to accomplish this.

ohler55 commented 11 months ago

Right now there is not a way to control the output format other than the precision.

bryanp commented 11 months ago

Is this a change you'd be open to seeing? I'm thinking of a new float_format option that is a format string.

ohler55 commented 11 months ago

Possibly. I'll be messing with the options this weekend. I could add that in.

ohler55 commented 10 months ago

Please try the "more-options" branch.

bryanp commented 10 months ago

This looks like exactly what I'm after!

ohler55 commented 10 months ago

Release v3.16.0 with the fix.