Conversion rules float to/from unsigned integer
Moderator: Benj
Conversion rules float to/from unsigned integer
Hi,
My project requires conversion of (unsigned)integer to floating point and back. I've seen some anomalies in equations where I thought the conversion was inplicit but did not give the expected result.
I perused the Help file but it only gives rules for floating point operations as such, no conversion rules.
Are these available somewhere?
While I am at it: is it correct that the rounding function fround is not available for 16Fxxx PIC processors?
Jan Didden
My project requires conversion of (unsigned)integer to floating point and back. I've seen some anomalies in equations where I thought the conversion was inplicit but did not give the expected result.
I perused the Help file but it only gives rules for floating point operations as such, no conversion rules.
Are these available somewhere?
While I am at it: is it correct that the rounding function fround is not available for 16Fxxx PIC processors?
Jan Didden
Re: Conversion rules float to/from unsigned integer
Hi Jan,
What sort of resolution are you looking for from the float to int conversion? it should be possible to do something like this.
intwhole = float2int( float )
floattemp = float  intwhole
floattemp = floattemp * 1000
intreal = float2int( floattemp )
Yes this is not available for 8bit PICs in Flowcode v5 and v6, it is available via the new compiler used in v7.is it correct that the rounding function fround is not available for 16Fxxx PIC processors?
What sort of resolution are you looking for from the float to int conversion? it should be possible to do something like this.
intwhole = float2int( float )
floattemp = float  intwhole
floattemp = floattemp * 1000
intreal = float2int( floattemp )
Regards Ben Rowland  MatrixTSL
Flowcode Product Page  Flowcode Help Wiki  Flowcode Examples  Flowcode Blog  Flowcode Course  My YouTube Channel
Flowcode Product Page  Flowcode Help Wiki  Flowcode Examples  Flowcode Blog  Flowcode Course  My YouTube Channel
Re: Conversion rules float to/from unsigned integer
Thanks Ben, that is very helpful. I thought that something like fSomething = fSomethingElse + uiNumber would implicitly convert the ui before doing the operation but it is not consistent.
I was not aware of the float2int function.
Can I assume there is also an int2float? Is there a list of these functions somewhere?
I will check out FC7 for te fround; in fact I think I have upgraded to FC7 (and FC6 before that) but I am so used to FC5 that it's hard to say goodby to it...
Jan
I was not aware of the float2int function.
Can I assume there is also an int2float? Is there a list of these functions somewhere?
I will check out FC7 for te fround; in fact I think I have upgraded to FC7 (and FC6 before that) but I am so used to FC5 that it's hard to say goodby to it...
Jan
Re: Conversion rules float to/from unsigned integer
Hi Jan,
Yes there is an int2float and the functions can be found in the Fx tab of the calculation icon properties.
V6 and v7 take a bit of getting used to (v7 less so than v6) but I vastly prefer them to v5 now I've gotten used to them.
Yes there is an int2float and the functions can be found in the Fx tab of the calculation icon properties.
V6 and v7 take a bit of getting used to (v7 less so than v6) but I vastly prefer them to v5 now I've gotten used to them.
Regards Ben Rowland  MatrixTSL
Flowcode Product Page  Flowcode Help Wiki  Flowcode Examples  Flowcode Blog  Flowcode Course  My YouTube Channel
Flowcode Product Page  Flowcode Help Wiki  Flowcode Examples  Flowcode Blog  Flowcode Course  My YouTube Channel
Re: Conversion rules float to/from unsigned integer
I bit the bullet and upgraded to FC7
But I am getting stuck with the Supp Code for EEPROM presetting. Would be nice if you could take a look at my latest post in the FC7 forum.
But I am getting stuck with the Supp Code for EEPROM presetting. Would be nice if you could take a look at my latest post in the FC7 forum.
Re: Conversion rules float to/from unsigned integer
Congratulations, let us know how you get on.
I've replied to your other topic now.
I've replied to your other topic now.
Regards Ben Rowland  MatrixTSL
Flowcode Product Page  Flowcode Help Wiki  Flowcode Examples  Flowcode Blog  Flowcode Course  My YouTube Channel
Flowcode Product Page  Flowcode Help Wiki  Flowcode Examples  Flowcode Blog  Flowcode Course  My YouTube Channel
Re: Conversion rules float to/from unsigned integer
Hello! Ben
good afternoon
I am able to increment/decrement the float variable, but cannot convert the float(100.5) back to integer along with the decimal value with the above calculation.
I created the variables as below
intwhole as a Integer variable
float as Float variable
floattemp as Float variable
intreal as Integer variable
Something wrong I think, can you correct?
Thank you.
Abhi
Edit: I just noticed after posting, I post in V5 while I am using V8, need to change the version? kindly correct.
good afternoon
May I request you to help me with this conversion, I tried to do as mentioned above but without success.
I am able to increment/decrement the float variable, but cannot convert the float(100.5) back to integer along with the decimal value with the above calculation.
I created the variables as below
intwhole as a Integer variable
float as Float variable
floattemp as Float variable
intreal as Integer variable
Something wrong I think, can you correct?
Thank you.
Abhi
Edit: I just noticed after posting, I post in V5 while I am using V8, need to change the version? kindly correct.
Re: Conversion rules float to/from unsigned integer
Hi Abhi,
Can you post your program and we will have a look for you.
the following lines might be better as
floattemp = float  FLOAT intwhole
floattemp = floattemp * 1000.0
Can you post your program and we will have a look for you.
the following lines might be better as
floattemp = float  FLOAT intwhole
floattemp = floattemp * 1000.0
Regards Ben Rowland  MatrixTSL
Flowcode Product Page  Flowcode Help Wiki  Flowcode Examples  Flowcode Blog  Flowcode Course  My YouTube Channel
Flowcode Product Page  Flowcode Help Wiki  Flowcode Examples  Flowcode Blog  Flowcode Course  My YouTube Channel
Re: Conversion rules float to/from unsigned integer
Hi! Ben
Thanks for the reply, excuse me for the delay, it took some time to take out the required from the main chart.
I check the chart with F8, on every count the UP key will increment the count by 0.1 to 100 (and also decrement well), after five loop the count will be 100.5, I want to save the 100.5 to the Temporary_Variable pressing the enter key, I tried as you explained in the post, but I think I am making some mistake.
Thank you.
Abhi
Thanks for the reply, excuse me for the delay, it took some time to take out the required from the main chart.
I check the chart with F8, on every count the UP key will increment the count by 0.1 to 100 (and also decrement well), after five loop the count will be 100.5, I want to save the 100.5 to the Temporary_Variable pressing the enter key, I tried as you explained in the post, but I think I am making some mistake.
Thank you.
Abhi
 Attachments

 FloatTOInt_05092020.fcfx
 (15.75 KiB) Downloaded 1 time
Re: Conversion rules float to/from unsigned integer
Don't use FLOAT, you don't need it.
If you have a number what is needed to be increment or decrement by 0.1, multiply everything by 10. In this case, 1004 means 100.4 You have to make some tricks only if you want to display it as a Float.
x=1004 (the original number, means 100.4)
y=x mod 10 (y will be 4)
x=x/10 (x will be 100)
Display x, display decimal point, display y.
Yes, using division require lots of steps, it takes time but at the end, you can spare tons of RAM. If the process is slow, increase the speed of the controller. I don't now but I think, calculating with FLOAT also takes lots of steps/times.
If you have a number what is needed to be increment or decrement by 0.1, multiply everything by 10. In this case, 1004 means 100.4 You have to make some tricks only if you want to display it as a Float.
x=1004 (the original number, means 100.4)
y=x mod 10 (y will be 4)
x=x/10 (x will be 100)
Display x, display decimal point, display y.
Yes, using division require lots of steps, it takes time but at the end, you can spare tons of RAM. If the process is slow, increase the speed of the controller. I don't now but I think, calculating with FLOAT also takes lots of steps/times.
Re: Conversion rules float to/from unsigned integer
Hello! Bachman
Thanks for your answer, I will try to understand and implement your suggestion, I also need to save the value in EEPROM.
Thank you again.
Abhi
Thanks for your answer, I will try to understand and implement your suggestion, I also need to save the value in EEPROM.
Thank you again.
Abhi