Quantcast
Channel: LiveCode Forums
Viewing all articles
Browse latest Browse all 549

Getting Started with LiveCode - Complete Beginners • Re: JSONExport - rounding weirdness

$
0
0
@KimD: So the lines:

CODE:

Put (1000.001) into dataForApi["quantity_product"]Put (1000001/1000) into dataForApi["quantity_product"]
Are not quite the same.

In the first line '1000.001' is actually treated internally as a string (for various irksome reasons that are very difficult to change), this means that JSONExport sees it as a string and so exports it as a JSON String "1000.001".

In the second line the 1000001/1000 is a math op, so the result of the division is internally a number (floating point double specifically), this means that JSONExport sees it as a number and so exports it as a JSON Number 1000.001 *but* due to the LCB number->string method used to do so, precision is lost and it ends up coming out as 1000.

This has been fixed in LC10 where we've used a much better double->string conversion method.

[ Further, JSON import/export has been completely overhauled in Create 1.0 - where the same rules are used for emitting JSON numbers as the ECMA standards specify for JavaScript ]

Statistics: Posted by LCMark — Tue Oct 15, 2024 6:32 am



Viewing all articles
Browse latest Browse all 549

Trending Articles