cognitect / transit-cljs

Transit for ClojureScript
http://transit-format.org
Apache License 2.0
323 stars 20 forks source link

Decimal numbers are turned to ints when used as map keys #25

Closed Jannis closed 7 years ago

Jannis commented 8 years ago

When using decimal numbers such as 123.456 as keys in maps, they are incorrectly turned into integers (~i123.456) when writing them with transit:

cljs.user=> (transit/write (transit/writer :json) {123.456 :foo})
"[\"^ \",\"~i123.456\",\"~:foo\"]"

Standalone decimals are fine:

cljs.user=> (transit/write (transit/writer :json) 123.456)
"[\"~#'\",123.456]"
swannodette commented 7 years ago

All JS numbers are doubles. There's no reliable way to detect integers, so for performance reasons we opted to interpret numbers as integers as that's far more common in the web use case. If you need floats you need to wrap them yourself first.