Monte Goulding's day off? ; -) mergJSON - Documented Bug or Feature?
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
> whole point of what I was getting at.
> "I suppose there could be an option to choose a 'number of decimal
> 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
> can I be losing any precision if 2.30 is what's in the file?. The
> though would be a good idea but in the calling routine to MergJSON.. If
> is left blank or false then it uses the current setting of number
> 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
> 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
> 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 + 0
As numbers are rounded using numberFormat when converted to strings.
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps
More information about the Use-livecode