Stop Integer Coercion to Scientific Notation in JSON
Sannyasin Brahmanathaswami
brahma at hindu.org
Thu Sep 12 14:41:09 EDT 2019
Been working Panos off list.
There is a caveat, jsonImport and jsonExport not only "display" but "preserve" the scientific notation as a literal string and math will fail.
Panos says: must use, (and include in a standalone) mergeJson to use: jsonToArray and arrayToJSON
try these:
on mouseup
local tJSON
breakpoint
put "{" & quote & "lastRunDate" & quote && ":" && the seconds & "}" into tJSON
put jsonImport(tJSON) into tArr
put (tArr["lastRunDate"] +3600 ) into tArr["lastRunDate"]
put jsonExport(tArr) into tJSON
put tJSON into url ("binfile:" & (specialFolderPath("desktop") &"/myPrefs.json" ))
put url ("binfile:" & (specialFolderPath("desktop") &"/myPrefs.json" )) into tNewJSON
put jsonImport(tNewJSON) into tPreferencesA
put tPreferencesA["lastRunDate"] + 3600
end mouseup
# then try this
on mouseup
local tJSON
put "{" & quote & "lastRunDate" & quote && ":" && the seconds & "}" into tJSON
breakpoint
put jsonToArray(tJSON) into tArr
put (tArr["lastRunDate"] +3600 ) into tArr["lastRunDate"]
put arrayToJSON(tArr) into tJSON
put tJSON into url ("binfile:" & (specialFolderPath("desktop")&"/myPrefs.json" ))
put url ("binfile:" & (specialFolderPath("desktop") &"/myPrefs.json" )) into tNewJSON
put jsonImport(tNewJSON) into tPreferencesA
put the seconds &cr& tPreferencesA["lastRunDate"] +3600
end mouseup
Solved!
BR
Hello all,
There is not a lost of precision in the operations. The problem is just that LCB *displays* the value of large numbers in scientific notation, but if you actually do any calculations with the variables that hold these numbers, the calculations are accurate.
In other words the variables do hold the full value - it is the emission which is turning them into the scientific notation.
(emisson as text in json)
Hope this helps.
Kind regards,
Panos
--
On Wed, 11 Sep 2019 at 16:29, Sannyasin Brahmanathaswami via use-livecode <mailto:use-livecode at lists.runrev.com> wrote:
One tries his best to not get excited by bugs that are left untouched, With some OS's to. keep current, engineering has a tough time, we all know that … but this one pushes a button…
bug https://quality.livecode.com/show_bug.cgi?id=18159
More information about the use-livecode
mailing list