• Status: Solved
• Priority: Medium
• Security: Public
• Views: 722

# 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
0
mscproj
1 Solution

Commented:
No, there is no function to do that, but i wrote it for you:

<%@ 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>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<BODY>
<%
Response.Write(ceil("222.23"))
%>
<P>&nbsp;</P>

</BODY>
</HTML>

xabi
0

Commented:
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>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<BODY>
<%
Response.Write(ceil("222.23"))
%>
<P>&nbsp;</P>

</BODY>
</HTML>
0

Commented:
Try "Round"

;->
0

Commented:
VBScript:

Function CeilNum(i, n)
Dim k

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

0

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

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

jkunal, round(33.2) = 33!
0

Commented:
Yuri:
ceil(222.2223) ???

xabi
0

Author Commented:
Thanks!
0

function myceil(num)
sTmp = cstr(num)
iPosPoint = instr(1,sTmp,".")
myceil=cint(mid(STmp,1,iPosPoint-1))+1
end function
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.