Rounding

G

Guest

Victor Bazarov said:
That would be ill-advised. ceil(0.1) gives 1, which actually
should be 0 AFA rounding is concerned, no?

I realized it as soon as I posted my response; still, I will use the
incomplete requirement as an excuse:

"Say I have the number 15.7, how can I round it up to 16?"

:)

Ali

Note: I've found at least one reference on the web, which mentions the use
of a ceil-like functionality under the title "Rounding up." :)

http://support.microsoft.com/default.aspx?scid=kb;en-us;196652
 
V

Victor Bazarov

Ali said:
I realized it as soon as I posted my response; still, I will use the
incomplete requirement as an excuse:

"Say I have the number 15.7, how can I round it up to 16?"

:)

Ali

Note: I've found at least one reference on the web, which mentions
the use of a ceil-like functionality under the title "Rounding up." :)

http://support.microsoft.com/default.aspx?scid=kb;en-us;196652

Yes, we both used what is allowed on Usenet and sometimes leads to
unexpected results -- assumptions :) I assumed the requirement was
to round in the general sense, you used the precise requirements
stated in the posting. Either can be incorrect.

V
 
P

Pete Becker

Victor said:
That would be ill-advised. ceil(0.1) gives 1, which actually
should be 0 AFA rounding is concerned, no?

Usually, but if the rounding mode is round upward or round away from
zero then 1 is right (but not right for negative numbers in the latter
case). <g>
 
M

M

I realized it as soon as I posted my response; still, I will use the
incomplete requirement as an excuse:

"Say I have the number 15.7, how can I round it up to 16?"

:)

Ali

He didn't say up or nearest so it's a pretty good excuse.

He also didn't say what he wanted to do with the rounded value.

Usually, when I'm rounding, it's for printing output. If that's the
case here, then one can use formatting:

printf("The number is: %.0f\n", num");
or
cout.setf(cout.fixed, cout.floatfield);
cout.precision(0);
cout << "The number is: " << num << endl;
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top