Solved

Ceil function

Posted on 2000-02-29
8
714 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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 information …
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 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