P
pete
fdunne2 said:Is there a function in C that rounds off a float to an int?
e.g. 8.968 -> 9 or 3.217 -> 3.
Look up ceil() and floor(), from math.h
fdunne2 said:Is there a function in C that rounds off a float to an int?
e.g. 8.968 -> 9 or 3.217 -> 3.
pete said:Look up ceil() and floor(), from math.h
fdunne2 said:Is there a function in C that rounds off a float to an int?
e.g. 8.968 -> 9 or 3.217 -> 3.
Regards,
F.
This group is about standard C. Standard C has included functions such asfdunne2 said:Is there a function in C that rounds off a float to an int?
e.g. 8.968 -> 9 or 3.217 -> 3.
Regards,
F.
nrk said:Neither of which do what the OP wants. Perhaps something like:
double f; /* to be rounded */
...
int i = ( f < 0 ) ? f - 0.5 : f + 0.5;
with some care to avoid integer overflow?
This group is about standard C.
Standard C has included functions such as lrint() for nearly 4 years now.
The Real one for this round function is this one given belowpete wrote:
> fdunne2 wrote:
>>
>> Is there a function in C that rounds off a float to an int?
>> e.g. 8.968 -> 9 or 3.217 -> 3.
>
> Look up ceil() and floor(), from math.h
>
Neither of which do what the OP wants. Perhaps something like:
double f; /* to be rounded */
....
int i = ( f < 0 ) ? f - 0.5 : f + 0.5;
with some care to avoid integer overflow?
-nrk.
--
Remove devnull for email
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.