11-17-2022 12:19 PM
Hi all,
I need send JSON string via HTTP. I used Flatten To JSON Function but if I have input type: double (named resistance) and value e.g. 0.0035 function return this string: {"resistance":0.0035000000000000000729} Why it is? How can I correct this to get string {"resistance":0.0035} ?
Thank you
11-17-2022 12:48 PM - edited 11-17-2022 12:50 PM
Welcome to a floating-point world where fractional numbers are stored as an approximation and not precisely.
0.0035 could be approximated as 0.0035000000000000000729 in the IEEE floating-point format.
https://en.wikipedia.org/wiki/Floating-point_error_mitigation
11-17-2022 01:11 PM
Understand. But do you have any idea how to do it to get string {"resistance":0.0035} ? 😞
11-17-2022 02:16 PM
If you use JSONtext to do the conversion you will get 0.0035. The inbuilt JSON functions are designed to preserve floating-point values, rather than decimal numbers that humans work with.
11-25-2022 03:41 AM
Thank you. JSONtext works as I expected. 😉