Round to next value

  • Thread starter Thread starter RP
  • Start date Start date
R

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?
 
RP said:
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
 
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
 
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
 
Arne said:
There are two possible causes:
- bankers rounding
- floating point

Try:

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

Floor

Arne
 

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

Similar Threads

Rounding decimals to interger 3
Round function? 3
Round 3
Custom decimal round 14
Excel Stop Excel from displaying rounded values 4
Math.round 1
Rounding 2
Number Rounding/Formating 4

Back
Top