Decimals rounded

shamal

Registered User.
Local time
Today, 15:22
Joined
Sep 28, 2013
Messages
86
Hi....
How can the numbers rounded form:
If the numbers were from 24.01 to 25 are rounding.

If from 49.26 to 50 are rounding
If from 74.51 to be rounding to 75
thank to help me
 
just create a user-define function in a module:

public function fnRound(dblNumber As Double) As Long
fnRound = Int(dblNumber)
if dblNumber - fnRound <> 0 then fnRound = fnRound + 1
End Function
 
Thanks nice idea
 
mr.cj_london, i tried your code using odd whole number and its rounding up.

round(1 + 0.5, 0) = 2
round(3 + 0.5, 0) = 4
 
good point - in that case it would be

round(mynumber+0.49,0)
 
hello again mr.cj, if you dont mind, testing on the op's first post (24.01), using your round(24.01 + 0.49), the result is still 24, should be 25.
 
You can round to any number using this expression . . .
Code:
Function RoundToNearest(Number As Single, Optional RoundTo As Single = 1)
[COLOR="Green"]   '1) divide your number by what you want to round to,
   '2) round that result, and
   '3) multiply by what you want to round to
[/COLOR]    RoundToNearest = CLng(Number / RoundTo) * RoundTo
End Function
So shamal, it looks like you want to round to the nearest 25, so do . . .
Code:
Debug.Print RoundToNearest(24.01, 25)
Debug.Print RoundToNearest(49.26, 25)
Debug.Print RoundToNearest(74.51, 25)
 

Users who are viewing this thread

Back
Top Bottom