A user has reported a bug in a LC app that I developed four years ago, so I'm back into LC after an 18 month break. Within my app I'm converting Kg values entered by the user into Mt, by dividing the Kg value by 1000. There is no problem when the user inputs a Kg value which is less than 1 million, but if the user enters a Kg value over 1 million then - when they retrieve previously JSONExported data - they see their entered values have been rounded incorrectly. The bug is easy to reproduce with the following code -
Local dataForApi, JSONFile
Put "file:" & specialFolderPath("desktop") & slash & "RoundingWeirdness.txt" into JSONFile
Put empty into URL(JSONFile)
Put (1000.001) into dataForApi["quantity_product"]
Answer dataForApi["quantity_product"]
Put JSONExport(dataForApi) & CR after URL(JSONFile)
Put (1000001/1000) into dataForApi["quantity_product"]
Answer dataForApi["quantity_product"]
Put JSONExport(dataForApi) & CR after URL(JSONFile)
Both Answer dialogues display 1000.001 (the expected result), but the resulting RoundingWeirdness.txt file contains -
{"quantity_product": "1000.001"}
{"quantity_product": 1000}
The 2nd entry in the RoundingWeirdness.txt file is wrong; it should be 1000.001. If the problem was solely with the operation of dividing 1000001 by 1000, then I would have expected the 2nd answer dialogue to also display an incorrect result; but it doesn't. If the problem was solely with JSONExport, then I would have expected JSONExporting 1000.001 to also produce an incorrect result; but it doesn't.
JSONExporting 1000001/1000 does not produce the same result as JSONExporting 1000.001; which it should.
I'm pretty confident that I can easily create a work around for this, but I thought that I'd check whether this was a known issue.
LC 9.6.9rc2 on Windows 11.
Local dataForApi, JSONFile
Put "file:" & specialFolderPath("desktop") & slash & "RoundingWeirdness.txt" into JSONFile
Put empty into URL(JSONFile)
Put (1000.001) into dataForApi["quantity_product"]
Answer dataForApi["quantity_product"]
Put JSONExport(dataForApi) & CR after URL(JSONFile)
Put (1000001/1000) into dataForApi["quantity_product"]
Answer dataForApi["quantity_product"]
Put JSONExport(dataForApi) & CR after URL(JSONFile)
Both Answer dialogues display 1000.001 (the expected result), but the resulting RoundingWeirdness.txt file contains -
{"quantity_product": "1000.001"}
{"quantity_product": 1000}
The 2nd entry in the RoundingWeirdness.txt file is wrong; it should be 1000.001. If the problem was solely with the operation of dividing 1000001 by 1000, then I would have expected the 2nd answer dialogue to also display an incorrect result; but it doesn't. If the problem was solely with JSONExport, then I would have expected JSONExporting 1000.001 to also produce an incorrect result; but it doesn't.
JSONExporting 1000001/1000 does not produce the same result as JSONExporting 1000.001; which it should.
I'm pretty confident that I can easily create a work around for this, but I thought that I'd check whether this was a known issue.
LC 9.6.9rc2 on Windows 11.
Statistics: Posted by KimD — Tue Oct 15, 2024 5:08 am