Monte Goulding's day off? ; -) mergJSON - Documented Bug or Feature?
Mark Waddingham
mark at livecode.com
Wed Jun 29 11:06:48 EDT 2016
On 2016-06-29 16:58, Lagi Pittas wrote:
> Hi Mark,
>
> Thanks for the replies. But your second response I don't understand and
> the
> whole point of what I was getting at.
>
> "I suppose there could be an option to choose a 'number of decimal
> places'
> option passed to the library - however, you will then potentially lose
> information in your numbers. Therefore, it is probably better to do the
> rounding in script after loading the JSON file."
>
> If "reals" are returned as strings anyway then if the real says 2.30
> how
> can I be losing any precision if 2.30 is what's in the file?. The
> option
> though would be a good idea but in the calling routine to MergJSON.. If
> it
> is left blank or false then it uses the current setting of number
> format
> or if there is a string then that will be the format it uses.
Ah - this is the critical point...
MergJSON uses a C library which converts the text of a JSON input into a
tree of values - these values are arrays, objects, numbers, strings,
booleans etc. i.e. The output of this library is then processed by the
external to convert it to a LiveCode array and string values...
This means that the external gets numbers from the JSON as IEEE754
doubles, and then has to format them for return as strings. As the
original string has already been converted to a number at this point,
the external must format the numbers with enough decimal places so that
you don't lose any information. Hence why you are probably best off
processing the output of the external in LiveCode Script, rounding any
numbers you know need to be rounded.
> If I look at the Arrays using the variable display in the debugger they
> are
> all showing as 2 decimals so I would expect them to export in the same
> format - or am I again missing something about the debugger?
> If added global variable xx in the debugger with value 1.3456 and that
> is
> how it shows and ll 2 decimal place prices still show the same so LC
> "knows" how I want to see them.
The debugger displayed values using the numberFormat settings - usually
6 decimal places.
However, an important thing to remember about LiveCode Script is that if
something is a string, then it will remain a string. You only get
actually numbers internally when you perform operations on values which
need to be numbers. So:
put 1.43858239402803492304
will display:
1.43858239402803492304
But:
put 1.43858239402803492304 + 0
will display:
1.438582
As numbers are rounded using numberFormat when converted to strings.
Warmest Regards,
Mark.
--
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps
More information about the use-livecode
mailing list