Solved

Ceil function

Posted on 2000-02-29
8
715 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
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
Industry Leaders: 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
If-Then-Else ASP problem 6 71
Html CheckBox obtain Its Value 5 37
Use Mid in Html 6 22
Building JSON Results Table FROM DB 9 35
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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