Forum Discussion
Altera_Forum
Honored Contributor
19 years agoround function
Hi,
I want to round a floating point number before I cast it to an int. So, round 3.6 to 4.0 I try using the function round and the compiler buys it but when I do round(3.6) or round(3.6,0) I get 0 What gives? Thanks, Mike2 Replies
- Altera_Forum
Honored Contributor
how about:
float x = 3.6; int y; y = (int)(x + 0.5); // (3.6+0.5 = 4.1 which will get dragged down to 4) - Altera_Forum
Honored Contributor
Yeah, I *guess*.
Not quite as elegant as round but truthfully it will probably execute much quicker than any round function anyway. It bothers me that round seems to be defined but doesn't really work the way I expect it to but after writing code for Nios for a year I should not be surprised. Thank you for the response BadOmen. Mike