Monte Goulding's day off? ; -) mergJSON - Documented Bug or Feature?
monte at appisle.net
Wed Jun 29 18:06:57 EDT 2016
I’m sorry mergJSON isn’t working out for you. It sounds to me like you actually want to represent your numbers as strings in the JSON. In which case mergJSON does have the facility to force things that look like numbers to be strings and things that look like sequentially indexed arrays to be unordered objects.
If you would like to read up on floating point precision there’s some information here https://en.wikipedia.org/wiki/Floating_point
LiveCode will format numbers using the current numberFormat when the user wants to use them as a string. This would probably be a reasonable change to the external too. mergJSON is open source so if anyone is so inclined they could use EvalExpr to get the numberFormat then do something like what the engine does in MCU_r8tos to format the string. The repository is at https://github.com/montegoulding/mergJson. We might want an extra boolean parameter governing whether to apply the numberFormat also I think.
> On 29 Jun 2016, at 9:22 PM, Lagi Pittas <iphonelagi at gmail.com> wrote:
> I used the mergJSON in version 8 DP1 today for the first time.
> I loaded my CSV file into the program and build my arrays then exported the
> array as JSON.
> what do I find?
> prices that were 1.40 showing up as 1.3999999999999999, 2.30 showing as
> 2.2999999999999998 etc
> Now I know this is documented as anything that looks like a real number is
> stored as an IEEE 754 double.
> Can someone please explain the logic that says that a textual
> representation of information (CSV, XML a text file even) is translated to
> a IEEE number for us to round as we see fit?
> Please explain any cases where this makes any sense at all.
> if I wanted the number to be 1.399999 thats what I would put in there.
> Now the documentation says round it to the precision you want - it already
> is otherwise it wouldn't be in the CSV/JSON file if it was wrong in the
> first place.
> Anyone got any thoughts on this?
> Monte as much as I respect your programming prowess I respectfully think
> you are wrong on this one - it has to be more coding to do it this way than
> to leave it as text - or am I missing something.
> Shouldn't there be a parameter that asks if we want this (with false as the
> default?) as per the pretty print which works brilliantly by the way -
> perfect in fact.
> I wrote a JSON library for Visual foxpro a couple of years ago and the only
> change it made was if there was an integer of say 1 or 2 it would change it
> to 1.0 or 2.0 because Foxpro itself reads any numbers from a file as Real
> rather than integer but the actual value is still the same 1.0 is 1. I
> could have coded against that but it would have been a bit convoluted and
> would have slowed the system down so I left it as is.
> KIndest Regards Lagi
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
More information about the Use-livecode