Link to home
Start Free TrialLog in
Avatar of mscproj
mscproj

asked on

Ceil function

Is there any ceil function on asp, and even pass the parameter of up to which decimal numbers.

E.g.
33.2 -> 34
33.8 -> 34

If pass parameter up to 1 decimal
33.24 -> 33.3
33.28 -> 33.3

If pass parameter up to 2 decimal
33.242 -> 33.25
33.246 -> 33.25
ASKER CERTIFIED SOLUTION
Avatar of xabi
xabi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xabi
xabi

Here goes with for easy reading:

<%@ Language=VBScript %>
<%
function ceil(number)
      if isNumeric(number) then
            sTmp      = cstr(number)
            iPosPoint = instr(1,sTmp,".")
            ceil = number
            if iPosPoint > 0 then
                  iNumDec = len(sTmp) - iPosPoint
                  if iNumDec > 0 then
                        sTmp = left(sTmp,iPosPoint-1) & right(sTmp, iNumDec - 1)
                        sTmp = cstr(clng(stmp + 1))
                        sTmp = left(sTmp,len(sTmp)-(iNumDec-1)) & "." & right(sTmp,iNumDec-1)
                        ceil = csng(sTmp)
                  else
                        ceil = cint(left(sTmp,iPosPoint-1))
                  end if
            end if
      else
            ceil = 0
      end if
end function
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<%
Response.Write(ceil("222.23"))
%>
<P>&nbsp;</P>

</BODY>
</HTML>
Try "Round"

;->
VBScript:

  Function CeilNum(i, n)
    Dim k

    k = CDbl("1e" & n)
    CeilNum = CInt(i * k) / k
  End Function

JavaScript:
  function ceilNum(i, n)
  {
    var k = parseFloat("1e" + n);

    return Math.ceil(i*k)/k;
  }

jkunal, round(33.2) = 33!
Yuri:
  ceil(222.2223) ???

xabi
Avatar of mscproj

ASKER

Thanks!
function myceil(num)
         sTmp = cstr(num)
          iPosPoint = instr(1,sTmp,".")
          myceil=cint(mid(STmp,1,iPosPoint-1))+1
 end function