casting question! Is this roudning to the nearest integer?.:Resolved:.
Hello everyone!
I'm reading some exericses and it wants me to round the number to the nearest integer. Okay this is quite easy I thought, but does this mean if i have:
34.6 to print 34
or does it mean
34.6 to print 35?
my code does the first thing, it prints 34 not 35.
Code:
double x = 34.6;
cout <<"x: " << static_cast<int>(x) << endl;
this just truncates the decimal number and prints 34! is this right?
Thanks for listening, :D
Re: casting question! Is this roudning to the nearest integer?
Quote:
Originally posted by voidflux
Hello everyone!
I'm reading some exericses and it wants me to round the number to the nearest integer. Okay this is quite easy I thought, but does this mean if i have:
34.6 to print 34
or does it mean
34.6 to print 35?
my code does the first thing, it prints 34 not 35.
Code:
double x = 34.6;
cout <<"x: " << static_cast<int>(x) << endl;
this just truncates the decimal number and prints 34! is this right?
Thanks for listening, :D
Nope, 34.6 rounded to the nearest integer is 35 (normally).