Solved

Ceil function

Posted on 2000-02-29
8
710 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
Comment Utility
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
Comment Utility
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
Comment Utility
Try "Round"

;->
0
 
LVL 10

Expert Comment

by:Yury_Delendik
Comment Utility
VBScript:

  Function CeilNum(i, n)
    Dim k

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

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 10

Expert Comment

by:Yury_Delendik
Comment Utility
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
Comment Utility
Yuri:
  ceil(222.2223) ???

xabi
0
 

Author Comment

by:mscproj
Comment Utility
Thanks!
0
 
LVL 4

Expert Comment

by:Sashi Rachabattula
Comment Utility
function myceil(num)
         sTmp = cstr(num)
          iPosPoint = instr(1,sTmp,".")
          myceil=cint(mid(STmp,1,iPosPoint-1))+1
 end function
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now