473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Rounding

Say I have the number 15.7, how can I round it up to 16?
Sep 14 '05 #1
8 7478
deanfamily11 wrote:
Say I have the number 15.7, how can I round it up to 16?


Add 0.5 and assign it to an integer.

V
Sep 14 '05 #2
floor(x+0.5)

Sep 14 '05 #3
<ke********@motioneng.com> wrote in message
news:11********************@g49g2000cwa.googlegrou ps.com...
floor(x+0.5)


ceil(x);

Ali

Sep 14 '05 #4
Ali Çehreli wrote:
<ke********@motioneng.com> wrote in message
news:11********************@g49g2000cwa.googlegrou ps.com...
floor(x+0.5)


ceil(x);


That would be ill-advised. ceil(0.1) gives 1, which actually
should be 0 AFA rounding is concerned, no?
Sep 14 '05 #5
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:kf********************@comcast.com...
Ali ehreli wrote:
<ke********@motioneng.com> wrote in message
news:11********************@g49g2000cwa.googlegrou ps.com...
floor(x+0.5)


ceil(x);


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...b;en-us;196652
Sep 14 '05 #6
Ali Cehreli wrote:
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:kf********************@comcast.com...
Ali ehreli wrote:
<ke********@motioneng.com> wrote in message
news:11********************@g49g2000cwa.googlegrou ps.com...
floor(x+0.5)

ceil(x);


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...b;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
Sep 14 '05 #7
Victor Bazarov wrote:

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>

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Sep 14 '05 #8
M
On Tue, 13 Sep 2005 18:05:23 -0700, Ali Çehreli <ac******@yahoo.com>
wrote:
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;
Sep 14 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Norvin Laudon | last post by:
Hi, Can somebody explain the following, from the MSDN documentation for the "System.Convert.ToInt32(double)" function <quote> Return Value value rounded to the nearest 32-bit signed...
4
by: spebola | last post by:
I am using vb.net 2003 professional and I get the following results when using the round method: dim Amount as decimal = 180.255 Amount = Amount.Round(Amount, 2) Amount now contains 180.25. ...
8
by: Zorpiedoman | last post by:
Howcome: Dim D as decimal = .5D msgbox d.Round(D, 0) this returns "0" Now when I went to school .5 rounds UP to 1 not DOWN to zero?????!!! Documentation says this, but what the heck are...
2
by: Jiri Nemec | last post by:
Hello all, I have got one table with rounding values, table contains prices and round types. id price_from price_to rounding 1 0 1500 0.1 2 1500 ...
11
by: cj | last post by:
Lets assume all calculations are done with decimal data types so things are as precise as possible. When it comes to the final rounding to cut a check to pay dividends for example in VB rounding...
18
by: jdrott1 | last post by:
i'm trying to round my currency string to end in 9. it's for a pricing application. this is the function i'm using to get the item in currency: FormatCurrency(BoxCost, , , , TriState.True) if...
5
by: Spoon | last post by:
Hello everyone, I don't understand how the lrint() function works. long lrint(double x); The function returns the nearest long integer to x, consistent with the current rounding mode. It...
206
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
20
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
30
by: bdsatish | last post by:
The built-in function round( ) will always "round up", that is 1.5 is rounded to 2.0 and 2.5 is rounded to 3.0. If I want to round to the nearest even, that is my_round(1.5) = 2 # As...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.