Feb 20, 2004 #1 andycape Programmer Joined Aug 22, 2003 Messages 177 Location ZA is there a way to round up a value in ASP? ie : "1.9" or "1.2" will both become "2" thanx
is there a way to round up a value in ASP? ie : "1.9" or "1.2" will both become "2" thanx
Feb 20, 2004 #2 foxbox Programmer Joined Sep 11, 2000 Messages 1,052 Location NL try this: var = 1.2 response.write int( var + 1) & "<br>" var = 1.9 response.write int( var + 1) see: http://www.devguru.com/Technologies/vbscript/quickref/Int.html notice the remark on negative numbers! hth, Foxbox Upvote 0 Downvote
try this: var = 1.2 response.write int( var + 1) & "<br>" var = 1.9 response.write int( var + 1) see: http://www.devguru.com/Technologies/vbscript/quickref/Int.html notice the remark on negative numbers! hth, Foxbox
Feb 20, 2004 #3 tsuji Technical User Joined Jul 25, 2001 Messages 10,675 Location US Hello all, Or rather Code: function Roundup(v) if int(v)=v then Roundup=v else Roundup=int(v+1) end function It's up to you to decide the behavior for v being negative. regards - tsuji Upvote 0 Downvote
Hello all, Or rather Code: function Roundup(v) if int(v)=v then Roundup=v else Roundup=int(v+1) end function It's up to you to decide the behavior for v being negative. regards - tsuji
Feb 20, 2004 #4 Tarwn Programmer Joined Mar 20, 2001 Messages 5,787 Location US If you use the Round function you can keep the function clean while also accounting for negative numbers: Code: Function RoundUp(num) If Round(num) < num Then RoundUp = Round(num+.5) Else RoundUp = Round(num) End Function Basically this should cover everything negative and positive without any extra work. -T 01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111 The never-completed website: http://www.tiernok.com/ Upvote 0 Downvote
If you use the Round function you can keep the function clean while also accounting for negative numbers: Code: Function RoundUp(num) If Round(num) < num Then RoundUp = Round(num+.5) Else RoundUp = Round(num) End Function Basically this should cover everything negative and positive without any extra work. -T 01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111 The never-completed website: http://www.tiernok.com/