Enjoy an ad free experience by logging in. Not a member yet? Register.

Results 1 to 6 of 6
Thread: does ASP have a Ceil function?

08152002, 01:06 PM #1
 Join Date
 Jun 2002
 Posts
 42
 Thanks
 0
 Thanked 0 Times in 0 Posts
does ASP have a Ceil function?
I have been looking around but can't seem to find anything on a Ceil function in asp. If anyone could help me figure out how to use it (if there is one) or a function to round a float up to the next highest int I would appreciate it.
08152002, 02:04 PM
#2
 Join Date
 Aug 2002
 Location
 Istanbul
 Posts
 5
 Thanks
 0
 Thanked 0 Times in 0 Posts
Hi,
You can use Round function
Dim MyFloat, NewFloat
MyFloat ="1988.721"
NewFloat = Round(MyFloat,0)
NewFloat will be equal to 1989 ( rounded up )
08152002, 03:33 PM
#3
 Join Date
 Jun 2002
 Location
 Plano, Texas
 Posts
 113
 Thanks
 0
 Thanked 0 Times in 0 Posts
Link Defines Math.ceil :
http://www.asphelp.com/getstarted/ms/jscript/76.asp
I use this function on a calculator html page to set rounding up/down etc.:
DemoCode:function custRound(x,places) { if (document.calc.RoundOpt.value == "Up") { places = 0 document.calc.Decimals.value = 0 return (Math.ceil(x*Math.pow(10,places)))/Math.pow(10,places) } if (document.calc.RoundOpt.value == "Down") { places = 0 document.calc.Decimals.value = 0 return (Math.floor(x*Math.pow(10,places)))/Math.pow(10,places) } if (document.calc.RoundOpt.value == "Normal") { NewNum = (Math.round(x*Math.pow(10,places)))/Math.pow(10,places) NewNum = new NumberFormat(NewNum) NewNum.setCommas(true) NewNum.setCurrency(false) NewNum.setPlaces(places) NewNum = NewNum.toFormatted(); return NewNum } }
Last edited by JoeP; 08152002 at 03:39 PM.
08162002, 07:13 AM
#4
 Join Date
 Jun 2002
 Posts
 42
 Thanks
 0
 Thanked 0 Times in 0 Posts
Thanks for the help but it keeps giving me an error saying 'Variable is undefined: 'Math' ' when I use Math.ceil. Is there some type of math file I should include or something (this is all in classic ASP by the way). Also just using round will not work because I do not want it to round down (so if it is 16.0001 I need it to go up to 17)
Thanks
08162002, 03:12 PM
#5
 Join Date
 Jun 2002
 Location
 Plano, Texas
 Posts
 113
 Thanks
 0
 Thanked 0 Times in 0 Posts
Here is a simpler form of the same thing. Should work fine in an ASP page. Notie you can round up or down getting the results you desire.
Code:<html> <body> <script language="Javascript"> function custRound(x,places) { if (document.calc.RoundOpt.value == "Up") { NewNum = (Math.ceil(x*Math.pow(10,places)))/Math.pow(10,places) } if (document.calc.RoundOpt.value == "Down") { places = 0 NewNum = (Math.floor(x*Math.pow(10,places)))/Math.pow(10,places) } alert(NewNum) } </script> <form name="calc" method="POST"> <input type="text" name="T1" size="20" value="16.0001"><br> <select size="1" name="RoundOpt"> <option selected value="Up">Up</option> <option value="Down">Down</option> </select> <input type="button" value="Round Number" onClick="custRound(document.calc.T1.value,0)"> </form> </body> </html>
10052009, 08:30 PM
#6
 Join Date
 Oct 2009
 Posts
 1
 Thanks
 0
 Thanked 0 Times in 0 Posts
ceil in asp
Hi,
well, it is simple to gain ceil in asp. Imagine: x = 1.1
If x > Int(x) Then
x = x + 1
End If
Response.Write Int(x)
That's it.
Happy programming.
albasiba