LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Flatten To JSON Function

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

0 Kudos
Message 1 of 5
(1,170 Views)

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

 

santo_13_0-1668711005674.png

 

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 2 of 5
(1,159 Views)

Understand. But do you have any idea how to do it to get string {"resistance":0.0035} ? 😞

0 Kudos
Message 3 of 5
(1,137 Views)

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.  

0 Kudos
Message 4 of 5
(1,118 Views)

Thank you. JSONtext works as I expected. 😉

0 Kudos
Message 5 of 5
(1,038 Views)