Click to See Complete Forum and Search --> : round a number up


deep-wood
01-24-2006, 05:19 PM
hi!

im dividing a number up, lets just say num1 = 5 and num2 = 15

answer = num2 + num1

this would give answer of 3 - alls great.

however, say num2 = 16. using that same equation gives an answer of 3.2
how would i get rid of the .2 bit to leave only 3?

would string replace work? and if so, how exactly do i do this?

thanks people

deep-wood
01-24-2006, 05:44 PM
i just looked on w3schools,

used this, <%response.write(FormatNumber(3.2,0))%> - which works, gives 3

however, <%response.write(FormatNumber(3.8,0))%> would give 4...so im even more stuck lol

cusimar9
01-25-2006, 05:05 AM
You were on the right lines... try FormatNumber(n-0.5,0) ;)

Ubik
01-25-2006, 12:42 PM
int(n-0.5,0) might also work.

obenjamin
01-25-2006, 01:40 PM
Why don't you go oldschool. We know that if you add .5 and it is not greater then int(num) it needs to be rounded down else it needs to be rounded up.
if(int(num+.5)=int(num))
num=int(num)
Else
num=int(num+1)