Solved

Ceil function

Posted on 2000-02-29
8
717 Views
Last Modified: 2008-02-01
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
Comment
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
  • Learn & ask questions
8 Comments
 
LVL 8

Accepted Solution

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

</BODY>
</HTML>

xabi
0
 
LVL 8

Expert Comment

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

</BODY>
</HTML>
0
 
LVL 4

Expert Comment

by:jkunal
ID: 2571786
Try "Round"

;->
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:Yury_Delendik
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

by:Yury_Delendik
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

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

xabi
0
 

Author Comment

by:mscproj
ID: 2575803
Thanks!
0
 
LVL 4

Expert Comment

by:Sashi Rachabattula
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question