Say I have the number 15.7, how can I round it up to 16?
Rounding
Collapse
This topic is closed.
X
X
-
deanfamily11Tags: None -
Victor Bazarov
Re: Rounding
deanfamily11 wrote:[color=blue]
> Say I have the number 15.7, how can I round it up to 16?[/color]
Add 0.5 and assign it to an integer.
V
-
kevin.hall@motioneng.com -
Ali Çehreli
Re: Rounding
<kevin.hall@mot ioneng.com> wrote in message
news:1126657174 .361506.7810@g4 9g2000cwa.googl egroups.com...[color=blue]
> floor(x+0.5)[/color]
ceil(x);
Ali
Comment
-
Victor Bazarov
Re: Rounding
Ali Çehreli wrote:[color=blue]
> <kevin.hall@mot ioneng.com> wrote in message
> news:1126657174 .361506.7810@g4 9g2000cwa.googl egroups.com...[color=green]
>> floor(x+0.5)[/color]
>
> ceil(x);[/color]
That would be ill-advised. ceil(0.1) gives 1, which actually
should be 0 AFA rounding is concerned, no?
Comment
-
Ali Çehreli
Re: Rounding
"Victor Bazarov" <v.Abazarov@com Acast.net> wrote in message
news:kfednSJkPd jy6breRVn-tg@comcast.com. ..[color=blue]
> Ali ehreli wrote:[color=green]
>> <kevin.hall@mot ioneng.com> wrote in message
>> news:1126657174 .361506.7810@g4 9g2000cwa.googl egroups.com...[color=darkred]
>>> floor(x+0.5)[/color]
>>
>> ceil(x);[/color]
>
> That would be ill-advised. ceil(0.1) gives 1, which actually
> should be 0 AFA rounding is concerned, no?[/color]
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." :)
Comment
-
Victor Bazarov
Re: Rounding
Ali Cehreli wrote:[color=blue]
> "Victor Bazarov" <v.Abazarov@com Acast.net> wrote in message
> news:kfednSJkPd jy6breRVn-tg@comcast.com. ..[color=green]
>> Ali ehreli wrote:[color=darkred]
>>> <kevin.hall@mot ioneng.com> wrote in message
>>> news:1126657174 .361506.7810@g4 9g2000cwa.googl egroups.com...
>>>> floor(x+0.5)
>>>
>>> ceil(x);[/color]
>>
>> That would be ill-advised. ceil(0.1) gives 1, which actually
>> should be 0 AFA rounding is concerned, no?[/color]
>
> 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...b;en-us;196652[/color]
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
Comment
-
Pete Becker
Re: Rounding
Victor Bazarov wrote:[color=blue]
>
> That would be ill-advised. ceil(0.1) gives 1, which actually
> should be 0 AFA rounding is concerned, no?
>[/color]
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>
--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Comment
-
M
Re: Rounding
On Tue, 13 Sep 2005 18:05:23 -0700, Ali Çehreli <acehreli@yahoo .com>
wrote:
[color=blue]
>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
>[/color]
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;
Comment
Comment