Link to home
Start Free TrialLog in
Avatar of indy500fan
indy500fan

asked on

How do I round to then nearest hundred?

Friends,

I have the following block of code:

    Private Sub CalculatePreQualifyingMoneyPayoutBelowFirstPlace(ByVal Position As Integer)
        BasePayout = GetBaseAmount(Position)
        MultiplicationOfBasePayoutAndPurseRemainder = BasePayout * PurseRemainder
        AdditionalPayout = MultiplicationOfBasePayoutAndPurseRemainder / QualifyingMoneyTotal
        AdditionalPayout = Math.Round(AdditionalPayout)
    End Sub

Now, it should round to the value of AdditionalPayout up, but how do I do it to the nearest hundred?  Now, this doesn't mean the nearest hundredth, it means to the nearest 100.

For example,

Assume the following
Dim BasePayout, PurseRemainder, MultiplicationOfBasePayoutAndPurseRemainder, AdditionalPayout, QualifyingMoneyTotal as Decimal

BasePayout = 9000
PurseRemainder = 112000
QualifyingMoneyTotal = 480000

I want AdditionalPayout to equal 2300, not 2250 as the calculation, without the rounding, would total.

Thanks in advance!

Regards,
Eric


BasePayout
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of indy500fan
indy500fan

ASKER

Nope, that doesn't work.  Your suggestion gives me 2200.  Any other suggestions?
Also remember that I ALWAYS want to round up.  Even if the result was 2210, I'd still want it to end up being 2300.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Bchoor and TimCottee, this solution works as long as the value is increased by 50

Thanks to both of you!
No I was wrong It doesn't work.

It needs to function like the MROUND Function in Excel.  Make sense?
how about this
math.Truncate(((AdditionalPayout - 1) / 100) +1) * 100
bchoor,

1st, do you want me to start a new question, so you can get additional points for additional help?

2nd, it's telling me Truncate is not a member of System.Math
Well crude, I'm trying to write a program that matches a spreadsheet, and I notice that some are actually rounded down, not always up as the person told me.  

The rounding format is as follows:

 - 49 and below is rounded down
 - 50 and above is rounded up.
If it's a different question then sure

For the truncate, I'm using VS 2005 with .NET 2.0 and it does exist

the problem with Math.Round is that when it's at 22.50 it'll round down to 22.00
so you can add +1, that should give you the round up  (22.51 --> 23)
as for 49, when you add +1, it'll give you the round down (22.50 --> 22)
for 2200, it will round down (22.01 --> 22)
for 2199, it will work fine (22.00 --> 22)

So slight change to my first post
AdditionalPayout = Math.Round((AdditionalPayout + 1) /100) * 100

HTH
~BC
BC,

Perfecto!!!