Page 1 of 1

Float to Int

Posted: Fri Mar 05, 2010 11:37 am
by g-slocombe
How do I convert from Int to Float and Float to Int, I want to do some calculations on values read from Analogue to Digital converter?. I can't see any function to do this in the calculation help file.
Regards Gary

Re: Float to Int

Posted: Fri Mar 05, 2010 12:42 pm
by Steve
"float2int" and "int2float" are the appropriate functions. These don't seem to be in the help file, but it should be obvious how to use them. They are listed in the "functions..." window in the calculation icon window.

Re: Float to Int

Posted: Fri Mar 05, 2010 3:29 pm
by g-slocombe
Thanks
Is there a Round to zero function?, I can use.
I trying to display the result of a calculation to the lcd
Cft=459.59
Mft=1.7276
ans=(A2d value - Cft)/Mft

I am doing this at the moment to try and get around it.
Adcft = int2float(Adcint)
Temp1ft = fsub(Adcft, Cft)
Xft = fdiv(Temp1ft, Mft)
Wholeint = float2int(Xft)
Wholeft = int2float(Wholeint)
Decft = fmod(Xft, Wholeft)
Decint = float2int(Decft)

lcd printnumber Wholeint
lcd printAscii "."
lcd printnumber Decint
eg 34.59

Regards Gary

Re: Float to Int

Posted: Fri Mar 05, 2010 4:52 pm
by Steve
try something like this:

Code: Select all

float1 = round(float2)