I'm making this money balncing thing, now if the number that the user enters, and devides by 4, lets say that a number that has 3 digits after the . (decimal) how do I make it round it? to the last 2 decimals?
Printable View
I'm making this money balncing thing, now if the number that the user enters, and devides by 4, lets say that a number that has 3 digits after the . (decimal) how do I make it round it? to the last 2 decimals?
If you have VB6, use the Round function.
Code:MyNum = Round(MyNum, 2)
thanks Megatron
also, how do I make it round down?
I believe you would need to extract the 2nd and 3rd numbers after the decimal and write your own code to round down or up as you see fit. If you always want it rounded down, just delete everything after the second decimal place. Hope that makes sense.
To round a number, use the Int function.
Code:MyNum = Int(MyNum)
I'm not sure that I understand hellswraith, and, is there a way to round the number down the way megratron told me:
mynum = Round(mynum, 2)
is there a code like that that will always round down?
the Int and Fix Functions always round down. I don't know one that always rounds down to a number of decimal places but you can make your own
Code:Private Function RoundDown(ByVal Number As Double, ByVal DP As Integer)
RoundDown = Int(Number * (10 ^ DP)) / (10 ^ DP)
End Function
The Round function does this.Quote:
I don't know one that always rounds down to a number of decimal places
that rounds to the nearest n dp, we want a function that rounds down
Round(5.678,2) = 5.68
RoundDown(5.678,2)=5.67
Why not just:
Round(5.678-0.005,2) = 5.67
thanks to all