Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Round up Number
Hi all....
Given: total = 18.01
I use FormatNumber(total,2), it give me 18.01
I use FormatNumber(total,0) it give me 18

I wanna to get 19, how should i do the code?? if there is any decimal
value, i wanna round it up to the next whole number

cheers

*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!

Report this thread to moderator Post Follow-up to this message
Old Post
D
10-18-04 08:55 AM


Re: Round up Number
Function RoundUp(n)
roundUp = Int(n) - CBool(CDbl(n) <> CLng(n))
End Function

That may work.  What that's trying to do is take the integer portion of your
number, 18, and then, take your original decimal number, compare it to a
integerized version of it, and if they are not the same, subtract -1 (false)
from the result.

Ray at home



<D> wrote in message news:OiFY73MtEHA.2072@TK2MSFTNGP10.phx.gbl...
> Hi all....
> Given: total = 18.01
> I use FormatNumber(total,2), it give me 18.01
> I use FormatNumber(total,0) it give me 18
>
> I wanna to get 19, how should i do the code?? if there is any decimal
> value, i wanna round it up to the next whole number
>
> cheers
>
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!



Report this thread to moderator Post Follow-up to this message
Old Post
Ray Costanzo [MVP]
10-18-04 08:55 AM


Re: Round up Number
Do you have to deal with negative numbers? If not then how about :

If total > FormatNumber(total,0) then
total = FormatNumber(total,0) + 1
End If

Cheers
Ken

<D> wrote in message news:OiFY73MtEHA.2072@TK2MSFTNGP10.phx.gbl...
> Hi all....
> Given: total = 18.01
> I use FormatNumber(total,2), it give me 18.01
> I use FormatNumber(total,0) it give me 18
>
> I wanna to get 19, how should i do the code?? if there is any decimal
> value, i wanna round it up to the next whole number
>
> cheers
>
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!



Report this thread to moderator Post Follow-up to this message
Old Post
Ken Schaefer
10-18-04 08:55 AM


Re: Round up Number
thanks. i'm not dealing wif neg number so teh code works fine. thanks
alot

cheers

*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!

Report this thread to moderator Post Follow-up to this message
Old Post
D
10-18-04 08:55 AM


Re: Round up Number
Ken Schaefer wrote on 18 okt 2004 in
microsoft.public.inetserver.asp.general:

> Do you have to deal with negative numbers? If not then how about :
>
> <D> wrote in message news:OiFY73MtEHA.2072@TK2MSFTNGP10.phx.gbl... 

> If total > FormatNumber(total,0) then
>     total = FormatNumber(total,0) + 1
> End If

Why use FormatNumber() ?

====== vbscript ========

function roundup(x)
If x > Int(x) then
roundup = Int(x) + 1
Else
roundup = x
End If
End Function

total = roundup(total)

=== or in jscript ===

<script runat=server language=jscript>

function roundup(x){
return Math.ceil(x)
}

</script>

<% ' if you dedault to vbscript
total = roundup(total)
%>

======================

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)


Report this thread to moderator Post Follow-up to this message
Old Post
Evertjan.
10-18-04 08:55 AM


Re: Round up Number
function roundup(x)
If x > Int(x) then
roundup = Int(x) + 1
Else
roundup = Int(x)  'note should be Int(x), not just x
End If
End Function

total = roundup(total)

"Evertjan." <exjxw.hannivoort@interxnl.net> wrote in message
news:Xns95865E422558Feejj99@194.109.133.29...
> Ken Schaefer wrote on 18 okt 2004 in
> microsoft.public.inetserver.asp.general:
> 
> 
>
> Why use FormatNumber() ?
>
> ====== vbscript ========
>
> function roundup(x)
>    If x > Int(x) then
>         roundup = Int(x) + 1
>    Else
>        roundup = x
>    End If
> End Function
>
> total = roundup(total)
>
> === or in jscript ===
>
> <script runat=server language=jscript>
>
> function roundup(x){
>    return Math.ceil(x)
> }
>
> </script>
>
> <% ' if you dedault to vbscript
>    total = roundup(total)
> %>
>
> ======================
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress,
> but let us keep the discussions in the newsgroup)
>



Report this thread to moderator Post Follow-up to this message
Old Post
Coz
10-22-04 08:55 PM


Re: Round up Number
Coz wrote on 22 okt 2004 in microsoft.public.inetserver.asp.general:

> "Evertjan." <exjxw.hannivoort@interxnl.net> wrote in message 
> function roundup(x)
>     If x > Int(x) then
>          roundup = Int(x) + 1
>     Else
>         roundup = Int(x)  'note should be Int(x), not just x
>     End If
>  End Function
>
>  total = roundup(total)
>

[please do not toppost]

"should be Int(x)":
Not quite, as Ken specified "positive numbers only".


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)


Report this thread to moderator Post Follow-up to this message
Old Post
Evertjan.
10-23-04 01:55 PM


Re: Round up Number
The simplest way is:

FormatNumber((total + .99999999), 0)

<D> wrote in message news:OiFY73MtEHA.2072@TK2MSFTNGP10.phx.gbl...
> Hi all....
> Given: total = 18.01
> I use FormatNumber(total,2), it give me 18.01
> I use FormatNumber(total,0) it give me 18
>
> I wanna to get 19, how should i do the code?? if there is any decimal
> value, i wanna round it up to the next whole number
>
> cheers
>
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!



Report this thread to moderator Post Follow-up to this message
Old Post
Dave
10-31-04 08:55 AM


Re: Round up Number
Dave wrote on 31 okt 2004 in microsoft.public.inetserver.asp.general:

> The simplest way is:
>
> FormatNumber((total + .99999999), 0)
>

FormatNumber(total + .99999999, 0) is simpler

both will fail miserably however on:

total=3.999999992

resulting in 5

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)


Report this thread to moderator Post Follow-up to this message
Old Post
Evertjan.
10-31-04 01:55 PM


Re: Round up Number
Function RoundUp(num1)
RoundUp = 0
If IsNumeric(num1) Then
RoundUp = FormatNumber(CDbl(num1) + .5,0)
End If
End Function


'dlbjr
'Pleading sagacious indoctrination!



Report this thread to moderator Post Follow-up to this message
Old Post
dlbjr
10-31-04 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

ASP archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:01 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.