Float to Int

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
g-slocombe
Posts: 38
Joined: Fri Nov 07, 2008 12:57 pm
Has thanked: 7 times
Been thanked: 4 times

Float to Int

Post 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

User avatar
Steve
Matrix Staff
Posts: 3431
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: Float to Int

Post 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.

g-slocombe
Posts: 38
Joined: Fri Nov 07, 2008 12:57 pm
Has thanked: 7 times
Been thanked: 4 times

Re: Float to Int

Post 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

User avatar
Steve
Matrix Staff
Posts: 3431
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: Float to Int

Post by Steve »

try something like this:

Code: Select all

float1 = round(float2)

Post Reply