JSONItem - incorrect numerical values

Not sure what is happening here… I’m on Xojo 2021 1.1 OSX Big Sur.
I have a simple JSON string thus:
{“sensor”:“xyz”,“time”:1564231,“data”:[48.75,2.30,212.22]}

when I do this:

Var jbuf As New JSONItem
jbuf.Load(s)

the “data” values in jbuf are show as:
[48.75,2.2999999999999998224,212.21999999999999886]

what am I missing here(or doing wrong)? Maybe its some Xojo oddness?.. :frowning:

TIA

It’s computers. Eg you cannot express 0.1 in Binary, you can only approximate it.

When showing the numbers you could use Format

Anyone know if there is a feature request to allow us to define the DecimalFormat? (and work as defined)

That’s computers binary base oddness to human eyes needing base 10 to understand a value.
More bits, more precision, more base 10 like results, less bits, more binary conversion loss.

If a computer has 32 bit to express a fractional number, let’s say 0.1, it does it as this:

That’s all sums of fractions of 1/2^x, +1, as mantissa, times 2^y as exponent

ahh I though tit was defaulting to something sensible but as Alberto points out the ‘decimal format’
is there. looks like it could be set but is now deprecated. looping through all the values and correcting them with format(string,"#.##") works

You could of course use Bob’s Decimal Plugin: Decimal Plugin