...

View Full Version : does ASP have a Ceil function?



Darksbane
08-15-2002, 02:06 PM
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.

kara
08-15-2002, 03:04 PM
Hi,

You can use Round function

Dim MyFloat, NewFloat

MyFloat ="1988.721"
NewFloat = Round(MyFloat,0)

NewFloat will be equal to 1989 ( rounded up )

JoeP
08-15-2002, 04:33 PM
Link Defines Math.ceil :

http://www.asp-help.com/getstarted/ms/jscript/76.asp

I use this function on a calculator html page to set rounding up/down etc.:


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
}
}


Demo (www.houseofproctor.com/demos/calculator.htm)

Darksbane
08-16-2002, 08:13 AM
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

JoeP
08-16-2002, 04:12 PM
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.



<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>

albasiba
10-05-2009, 09:30 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum