Re: Float serialization adds digits?

14 views
Skip to first unread message
Message has been deleted
Message has been deleted

Igmar Palsenberg

unread,
Aug 8, 2017, 7:31:34 AM8/8/17
to Play Framework
I opened a Scala worksheet and put that in:

    import play.api.libs.json

    val v: Float = 12.345f
    json.JsNumber(v)

The result is

    v: Float = 12.345
    res3: play.api.libs.json.JsNumber = 12.345000267028809

Where do the additional digits come from? They are very annoying and I would like to just see 12.345.
I am using Play 2.5.14, has it been fixed since maybe?

You can't represent 12.345 in a float number. Floats have binary representation, not decimal. The real value of 12.345 is actually 12.34500026702880859375



Igmar
 
Reply all
Reply to author
Forward
Message has been deleted
0 new messages