Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    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.

  • #2
    New to the CF scene
    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 )

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Plano, Texas
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 04:39 PM.

  • #4
    New Coder
    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

  • #5
    Regular Coder
    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>

  • #6
    New to the CF scene
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •