473,403 Members | 2,183 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,403 software developers and data experts.

Round to next value

RP
I want to ROUND the value if it is .5 or more to next integer. I am
using like this:

adAmount = Math.Round((basicPay * PerOrAmount) / 100, 0);

But it is not doing correctly. Suppose of adAmount = 132.5, it will
not do 133. If it exceeds .5 then it does. How to round when .5?

Aug 26 '07 #1
4 2363
RP wrote:
I want to ROUND the value if it is .5 or more to next integer. I am
using like this:

adAmount = Math.Round((basicPay * PerOrAmount) / 100, 0);

But it is not doing correctly. Suppose of adAmount = 132.5, it will
not do 133. If it exceeds .5 then it does. How to round when .5?
There are two possible causes:
- bankers rounding
- floating point

Try:

adAmount = Math.Fllor((basicPay * PerOrAmount) / 100 + 0.5);

Arne

Aug 26 '07 #2
On Sun, 26 Aug 2007 17:48:05 +0200, RP <rp*********@gmail.comwrote:
I want to ROUND the value if it is .5 or more to next integer. I am
using like this:

adAmount = Math.Round((basicPay * PerOrAmount) / 100, 0);

But it is not doing correctly. Suppose of adAmount = 132.5, it will
not do 133. If it exceeds .5 then it does. How to round when .5?

Hi RP,

Use the overloaded Math.Round specifying MidpointRounding.AwayFromZero

--
Happy coding!
Morten Wennevik [C# MVP]
Aug 26 '07 #3
You only needed to look the overloads of the method Math.Round, there is one
where you can specify the behavior when the number is just in the middle.

Specify the value MidpointRounding.AwayFromZero to round it to 133 or
MidpointRounding.ToEven to round it to 132.

Jose Fco Bonnin

"RP" <rp*********@gmail.comwrote in message
news:11**********************@q5g2000prf.googlegro ups.com...
>I want to ROUND the value if it is .5 or more to next integer. I am
using like this:

adAmount = Math.Round((basicPay * PerOrAmount) / 100, 0);

But it is not doing correctly. Suppose of adAmount = 132.5, it will
not do 133. If it exceeds .5 then it does. How to round when .5?
Aug 26 '07 #4
Arne Vajhøj wrote:
RP wrote:
>I want to ROUND the value if it is .5 or more to next integer. I am
using like this:

adAmount = Math.Round((basicPay * PerOrAmount) / 100, 0);

But it is not doing correctly. Suppose of adAmount = 132.5, it will
not do 133. If it exceeds .5 then it does. How to round when .5?

There are two possible causes:
- bankers rounding
- floating point

Try:

adAmount = Math.Fllor((basicPay * PerOrAmount) / 100 + 0.5);
Floor

Arne
Aug 26 '07 #5

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

Similar topics

6
by: Penguin | last post by:
At some long ago time Steve Jorgensen answered thus: Subject: Re: How can I round a time? Newsgroups: comp.databases.ms-access Date: 1998/12/11 Access represents a date internally as a double...
12
by: Test User | last post by:
Hi all, I have learnt that if I want to round 0.5 to an integer the result should be 1, This is also the case if I do it in SQL server 2000, but if I do it in VB.NET the result will be 0. ...
4
by: Fuzzydave | last post by:
I have been using a round command in a few places to round a value to zero decimal places using the following format, round('+value+', 0) but this consistantly returns the rounded result of...
7
by: kkmigas | last post by:
Can some one explain if this can be fixed using php.ini settings ? echo "round 20.545 -".round(20.545,2)."<br>"; echo "round 20.555 -".round(20.555,2)."<br>"; echo "number_format 20.545...
2
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
how do I code generic functions to return the next item in an enumeration a) sorted by name, b) sorted by value c) sorted by declaration in a round-robin style ? for example the enum is Enum...
4
by: lilmax88 | last post by:
I have a program in which I need to take a numeric value for dollars. There is a "set" function that must screen the value for the following 3 conditions with the indicated handling functionality:...
5
by: JackpipE | last post by:
I can't find anywhere function that will round double to next integer value: 1.1 -2 1.3 -2 1.9 -2 2 -2 Thanks for help, Jack
4
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
2
by: dkruger | last post by:
Hi Everyone, I am having a little problem that I am hoping someone can help me out with. In one of my scripts, I am working with some dollar values, and using round to change the result...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.