Hi ,
VBscript does the mathematical rounding:
If the last digit is 5, round it rounds to the EVEN number. Example: 5.265
would round to 5.26
but 5.275 would round to 5.28.
BUT I NEED it to round up if the last digit is 5 !! What function can I use?

Re: Rounding up by Th

Th
Sat Aug 30 17:16:42 CDT 2003

add 0.001 and round after...



Re: Rounding up by Leonardo

Leonardo
Sat Aug 30 19:23:07 CDT 2003


"Diana Castillo" <diana.castillo@nvtechnologies.com> escribió en el mensaje
news:u1oT1wzbDHA.724@tk2msftngp13.phx.gbl...
> Hi ,
> VBscript does the mathematical rounding:
> If the last digit is 5, round it rounds to the EVEN number. Example: 5.265
> would round to 5.26
> but 5.275 would round to 5.28.
> BUT I NEED it to round up if the last digit is 5 !! What function can I
use?

Hi, Diana:

If you know you are rounding after two decimal places you can write:

Function Redondeo(dArgumento)
Dim Signo, dRetVal
Signo = sgn(dArgumento)
dRetVal = dArgumento * Signo
dRetVal = Int(dRetVal * 100 + 0.5) / 100
Redondeo = dRetVal * Signo
End Function

Since Int always truncates the decimal part, adding one half will always
step to the next integer value, so when you divide back you will get the
expected value.

All the work with Signo is because you are going to Add a positive value
(0.5), and you expect it to grow to the next greater absolute value (in
order to keep the behaviour of Int).

A simpler version could be:

Function Redondeo(dArgumento)
Redondeo = Int(dArgumento * 100 + 0.5) / 100
End Function

but it would behave more like "Fix".

--
Salud!

Leonardo / MVP Visual Basic
leonardo<AT>lazpurua<DOT>com
www.lazpurua.com
Caracas, Venezuela