Code Comments
Programming Forum and web based access to our favorite programming groups.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!
Post Follow-up to this messageFunction 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!
Post Follow-up to this messageDo 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!
Post Follow-up to this messagethanks. 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!
Post Follow-up to this messageKen 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)
Post Follow-up to this messagefunction 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)
>
Post Follow-up to this messageCoz 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)
Post Follow-up to this messageThe 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!
Post Follow-up to this messageDave 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)
Post Follow-up to this messageFunction RoundUp(num1) RoundUp = 0 If IsNumeric(num1) Then RoundUp = FormatNumber(CDbl(num1) + .5,0) End If End Function 'dlbjr 'Pleading sagacious indoctrination!
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.