indy500fan
asked on
How do I round to then nearest hundred?
Friends,
I have the following block of code:
Private Sub CalculatePreQualifyingMone yPayoutBel owFirstPla ce(ByVal Position As Integer)
BasePayout = GetBaseAmount(Position)
MultiplicationOfBasePayout AndPurseRe mainder = BasePayout * PurseRemainder
AdditionalPayout = MultiplicationOfBasePayout AndPurseRe mainder / QualifyingMoneyTotal
AdditionalPayout = Math.Round(AdditionalPayou t)
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, MultiplicationOfBasePayout AndPurseRe mainder, 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
I have the following block of code:
Private Sub CalculatePreQualifyingMone
BasePayout = GetBaseAmount(Position)
MultiplicationOfBasePayout
AdditionalPayout = MultiplicationOfBasePayout
AdditionalPayout = Math.Round(AdditionalPayou
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, MultiplicationOfBasePayout
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bchoor and TimCottee, this solution works as long as the value is increased by 50
Thanks to both of you!
Thanks to both of you!
ASKER
No I was wrong It doesn't work.
It needs to function like the MROUND Function in Excel. Make sense?
It needs to function like the MROUND Function in Excel. Make sense?
how about this
math.Truncate(((Additional Payout - 1) / 100) +1) * 100
math.Truncate(((Additional
ASKER
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
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
ASKER
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.
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((AdditionalPayo ut + 1) /100) * 100
HTH
~BC
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((AdditionalPayo
HTH
~BC
ASKER
BC,
Perfecto!!!
Perfecto!!!
ASKER