06-15-2012 08:19 AM
Hi All,
I've tried and made a VI, which will determine the number of digits after decimal place.
Now if I choose to enter say "0.981" and run the VI, it returns 16 as the number of digits after decimal.
Now after selecting the "Display Format" of "Number In" I made following changes:
and now I found that "Number In" is actually equals to "0.98099999999999998300" and not "0.981".
Why is this happening?
06-15-2012 08:26 AM - edited 06-15-2012 08:27 AM
@moderator1983 wrote:
and now I found that "Number In" is actually equals to "0.98099999999999998300" and not "0.981".
Why is this happening?
That is happening because you have the number of digits of precision set to 20.
06-15-2012 08:43 AM
Please go through the VI and query once again.
I set the number of digits of precision to 20, just to probe, what exactly problem is....!!
06-15-2012 08:53 AM
I can't run your VIs. I only have LabVIEW 8.6
06-15-2012 08:58 AM - edited 06-15-2012 09:01 AM
Hello,
This effect has ben the subject of many threads, Search for rounding error, roundoff error, or similar terms.
The number 0.981 cannot be represented exactly in a floating point number format, such as DBL, so the number stored is an approximation - close to but not EXACTLY 0.981
When you repeatedly multiply by 10, and perform equality checks you are seeing the effects of this approximation. It is an inevitable part of the way non-integer numbers are stored.
It is common to get apparantly contadictory results when you perform equality checks on floats.
This does not just affect LabVIEW. You will see it in any language that operates on floating point numbers.
Rod.
06-15-2012 09:23 AM
IEEE 754-1985 defines the in-memory representation for floating point numbers. There should be lots of documents available to read out what happens.
06-15-2012 09:42 AM
Hmmnn Lot of replies, thank you everyone..
Now after I'm aware of why it is happening, can someone help me with actual problem:
"Determine the number of digits after decimal."
06-15-2012 09:50 AM
If you do not like Rod's idea: What do you expect?
06-15-2012 09:54 AM
If you want more control of the format for data entry, you could use a string control instead of a numeric.
As mentioned, any numeric control you use will end up with a IEEE representation.
If you just want to retrieve the precision you've selected for your numeric control, you can use a property node.
06-15-2012 10:09 AM
Hint: One way to avoid checking for equality in a real comparison is to check for the difference being sufficiently close to zero. Remember that the difference can be positive or negative. You will need to determine for yourself how close to zero "sufficiently" is for your application.
Rod.