Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Ceil function

Posted on 2000-02-29
Medium Priority
719 Views
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
Question by:mscproj
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 8

Accepted Solution

xabi earned 150 total points
ID: 2571783
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

LVL 8

Expert Comment

ID: 2571784
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

LVL 4

Expert Comment

ID: 2571786
Try "Round"

;->
0

LVL 10

Expert Comment

ID: 2571813
VBScript:

Function CeilNum(i, n)
Dim k

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

0

LVL 10

Expert Comment

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

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

jkunal, round(33.2) = 33!
0

LVL 8

Expert Comment

ID: 2571853
Yuri:
ceil(222.2223) ???

xabi
0

Author Comment

ID: 2575803
Thanks!
0

LVL 4

Expert Comment

ID: 8109250
function myceil(num)
sTmp = cstr(num)
iPosPoint = instr(1,sTmp,".")
myceil=cint(mid(STmp,1,iPosPoint-1))+1
end function
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
###### Suggested Courses
Course of the Month8 days, 18 hours left to enroll