Hi,
After calculation in my programm I get a float number eg: 363.08954.
I wish keep only 363, I don't want to convert into a string, but get an integer, this integer will be use again in my programm to determine a pixel position.
Any idea ?
Francis
How to get integer part of a float ?
-
- Posts: 172
- Joined: 24 Aug 2014 17:55
- Location: Sheffield
Re: How to get integer part of a float ?
Look at the c math library there are functions in there that will give you both the fraction part as well as the Integer part or just do this
Code: Select all
volatile float kad=363.4567;
volatile unsigned int int_part;
int_part=(unsigned int)kad;
"When the bugs strike it's no good bashing your head against a brick wall, you might damage the wall"
Re: How to get integer part of a float ?
Hello there FlyingRock (<--- Nice name )
Why don't you just define the result variable as an integer instead of a float?
In case that doesn't work for you, then please follow the advice of (Diode Blade), a guy with a cool name like that couldn't possibly give a bad advice
Kindest Regards
Why don't you just define the result variable as an integer instead of a float?
In case that doesn't work for you, then please follow the advice of (Diode Blade), a guy with a cool name like that couldn't possibly give a bad advice
Kindest Regards
My hobby is collecting MikroElektronika products.
Gotta catch them all!
Gotta catch them all!
-
- Posts: 45
- Joined: 12 Dec 2008 18:21
Re: How to get integer part of a float ?
Hi, diode_blade and MaGiK
Sorry to reply so late.
I didn't find function in math library to extract the integer part.
I tried what you have recommended and it's working.
Thank you for your help.
Sorry to reply so late.
I didn't find function in math library to extract the integer part.
I tried what you have recommended and it's working.
Thank you for your help.