LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Integer casting wrong?

I have not used CVI for 4 years and just now tried to use it agian w/ v.5.5.
I'm reading in a float value 58.3 But the variable window shown: 58.29999..
When I multiply this float value by 10.0 and cast it to an Integer variable, the value became 582.
If my initial float value is 58.7, the casting process went OK. What is wrong with this?
 
Also what is the modular function for getting an integer remeinder in CVI?
 
0 Kudos
Message 1 of 3
(2,896 Views)
Your might want to try RoundRealToNearestInteger() in CVIs Utility library.
The mod operator in C is the percent sign '%'
val=5%3;
val will be 2
 
 

Message Edited by mvr on 10-20-2005 01:23 PM

Message 2 of 3
(2,894 Views)
What you are seeing is actually the expected rounding behavior.  In ansi C, when you cast a floating point number to an integer, the remainder is dropped.  If your value was 58.29... then multiplying by 10 would give you 582.9... which, when cast to an integer, becomes 582.

Mert A.
National Instruments
0 Kudos
Message 3 of 3
(2,884 Views)