Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-15-2002, 01:06 PM   PM User | #1
Darksbane
New Coder

 
Join Date: Jun 2002
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Darksbane is an unknown quantity at this point
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.
Darksbane is offline   Reply With Quote
Old 08-15-2002, 02:04 PM   PM User | #2
kara
New to the CF scene

 
Join Date: Aug 2002
Location: Istanbul
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
kara is an unknown quantity at this point
Hi,

You can use Round function

Dim MyFloat, NewFloat

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

NewFloat will be equal to 1989 ( rounded up )
kara is offline   Reply With Quote
Old 08-15-2002, 03:33 PM   PM User | #3
JoeP
Regular Coder

 
Join Date: Jun 2002
Location: Plano, Texas
Posts: 113
Thanks: 0
Thanked 0 Times in 0 Posts
JoeP is an unknown quantity at this point
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.:
Code:
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

Last edited by JoeP; 08-15-2002 at 03:39 PM..
JoeP is offline   Reply With Quote
Old 08-16-2002, 07:13 AM   PM User | #4
Darksbane
New Coder

 
Join Date: Jun 2002
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Darksbane is an unknown quantity at this point
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
Darksbane is offline   Reply With Quote
Old 08-16-2002, 03:12 PM   PM User | #5
JoeP
Regular Coder

 
Join Date: Jun 2002
Location: Plano, Texas
Posts: 113
Thanks: 0
Thanked 0 Times in 0 Posts
JoeP is an unknown quantity at this point
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>
JoeP is offline   Reply With Quote
Old 10-05-2009, 08:30 PM   PM User | #6
albasiba
New to the CF scene

 
Join Date: Oct 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
albasiba is an unknown quantity at this point
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
albasiba is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:07 PM.


Advertisement
Log in to turn off these ads.