RJSONIO icon indicating copy to clipboard operation
RJSONIO copied to clipboard

fromJSON(toJSON(117229)) equals 117230 (???)

Open asieira opened this issue 11 years ago • 2 comments

It's as simple as that, numeric values are being corrupted when converted to JSON:

> toJSON(117229)
[1] "[ 1.1723e+05 ]"
> fromJSON(toJSON(117229))
[1] 117230

Perhaps there's some implicit conversion from double to float in the underlying C code?

asieira avatar Feb 05 '14 21:02 asieira

Thanks.

This is caused by formatC() in the toJSON method for numeric vectors. A workaround is either toJSON(117229L) # i.e. treat as an integer vector/scalar or toJSON(117229, digits = 6)

I'll take a look at how best to fix it generally.

duncantl avatar Feb 05 '14 21:02 duncantl

Thanks for the quick response. The workaround works perfectly.

Is there a simple way to ensure that digits=6 is always used across all my code? Some options variable that toJSON uses, for example?

asieira avatar Feb 05 '14 21:02 asieira