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.

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.
Hi,
You can use Round function
Dim MyFloat, NewFloat
MyFloat ="1988.721"
NewFloat = Round(MyFloat,0)
NewFloat will be equal to 1989 ( rounded up )
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.
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
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>
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