By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,134 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,134 IT Pros & Developers. It's quick & easy.

floating point round in C++

P: n/a
Hello, is there a way to implement the floating point version of round?
usually for int's it's int(num+.5) but how to do it for floats?

Thanks.
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"John Smith" <as**@asdf.com> wrote in message
news:br***********@news.eecs.umich.edu...
Hello, is there a way to implement the floating point version of round?
usually for int's it's int(num+.5) but how to do it for floats?

Thanks.


#include <math.h>

double d = floor(num+.5);
Jul 22 '05 #2

P: n/a
In article <br***********@news.eecs.umich.edu>, John Smith wrote:
Hello, is there a way to implement the floating point version of round?
usually for int's it's int(num+.5) but how to do it for floats?

[-]
Yeah ...

int(4.49 + 0.5)

.... sure 8-}

Just let me know which bank you're working for lest I'm opening
an account there.

Cheers,
Juergen

PS: C99 knows of round(double) and roundf(float).

--
\ Real name : Juergen Heinzl \ no flames /
\ EMail Private : ju*****@manannan.org \ send money instead /
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.