Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float JSON serialization outputs approxiamte value #109

Open
frozenspider opened this issue Jul 15, 2014 · 1 comment
Open

Float JSON serialization outputs approxiamte value #109

frozenspider opened this issue Jul 15, 2014 · 1 comment
Milestone

Comments

@frozenspider
Copy link

Using BasicFormats.FloatJsonFormat to serialize 1.85f of type Float yields 1.850000023841858 in the resulting JSON.
This is caused by the fact that JsNumber has no apply for Float, just for Double.
Proposal: add JsNumber.apply(Float).

Worst thing here is that there is no way to override/hide implicit BasicFormats.FloatJsonFormat since it's an object and not a value.

@lars-n
Copy link
Contributor

lars-n commented Nov 14, 2017

Came across this behaviour as well. The issue appears to be in JsNumber.apply (https://github.com/spray/spray-json/blob/master/src/main/scala/spray/json/JsValue.scala#L97) where the Float should be converted to a BigDecimal using BigDecimal.decimal rather than BigDecimal (see documentation there). Got a PR that adds a apply method for Floats to JsNumber: #241

@jrudolph jrudolph added this to the 1.3.6 milestone Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants