cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Can I get the exact value when generating JSON?

1,077

Query example:

select 1 as TAG,
       null as PARENT,
       '0' as "key", 7.27 as "value"
for json explicit

Result:

[["0",7.26999999999999881]]

As a result, value should be as in the original 7.27, the format of the field is numeric (12, 5)

[["0",7.27]]

I'll be grateful, cast, round, truncnum doesn't help

Accepted Solutions (0)

Answers (1)

Answers (1)

chris_keating
Product and Topic Expert
Product and Topic Expert

JSON numbers are either integer or double-precision floating point. Values like 7.27 cannot be expressed exactly as a floating point number. One option is to process these values as strings.

0 Kudos

I agree when the string value is - works correctly. But then you have to convert to floating point number when building in Google Charts. And this is extra time. Thank you for your answer, I will try

justin_willey
Participant

The problem is that at the end of the day, 2.7 cannot be accurately stored in base2 as a real number (just like 1/3 can't be exactly converted to base10) - you will always being dealing with some sort of approximation. Floating point numbers are a computer thing not a mathematical thing!

I think decimal datatypes (when available) are stored as integer values and the appropriate offset then applied.