Archived

This topic is now archived and is closed to further replies.

Converting Variables

This topic is 6939 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I've learned that the reslt will be 45, but I've never tested it.
If you want to round it, you have to write the following:
code:
float a = 45.426;int b;b = a + 0.5;

This should work... BYE

Share on other sites
As a complement to the post above, i can confirm that the value will be truncated, not rounded.

Share on other sites
Indeed it will be set to 45. Because it just chops the fraction off of it.......

------------------
Dance with me......

Share on other sites
Thanks for the help.

Share on other sites
Also, if you want to make sure of a value being set to one side or other of an integer you can use
double floor(double)...rounds down
and
double ceil(double)...rounds up
from Math.h

Share on other sites
What will result from this:

int x;
float y;

y = 45.54525252552
x = y;

Will x be rounded to 46, or will the fraction just get chopped? And if it is chopped, how can I force it to round up if the fraction is greater than or equal to 1/2?

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• Forum Statistics

• Total Topics
633709
• Total Posts
3013481
×