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.developersdex.com ***
Don't just participate in USENET...get rewarded for it! 12 35325
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:Oi**************@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.developersdex.com *** Don't just participate in USENET...get rewarded for it!
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:Oi**************@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.developersdex.com *** Don't just participate in USENET...get rewarded for it!
thanks. i'm not dealing wif neg number so teh code works fine. thanks
alot
cheers
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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:Oi**************@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
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)
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." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.29... 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:Oi**************@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
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)
Coz wrote on 22 okt 2004 in microsoft.public.inetserver.asp.general: "Evertjan." <ex**************@interxnl.net> wrote in message ====== 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 default to vbscript total = roundup(total) %>
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)
The simplest way is:
FormatNumber((total + .99999999), 0)
<D> wrote in message news:Oi**************@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.developersdex.com *** Don't just participate in USENET...get rewarded for it!
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)
Function RoundUp(num1)
RoundUp = 0
If IsNumeric(num1) Then
RoundUp = FormatNumber(CDbl(num1) + .5,0)
End If
End Function
'dlbjr
'Pleading sagacious indoctrination!
dlbjr wrote on 31 okt 2004 in microsoft.public.inetserver.asp.general: Function RoundUp(num1) RoundUp = 0 If IsNumeric(num1) Then RoundUp = FormatNumber(CDbl(num1) + .5,0) End If End Function
That is rounding, round-up is something else:
Function RoundUp(num1)
RoundUp = 0
If IsNumeric(num1) Then
RoundUp = Int(num1)
If num1 <> RoundUp Then
RoundUp = RoundUp + 1
End If
End If
End Function
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)
What is the difference in the result?
'dlbjr
'Pleading sagacious indoctrination!
dlbjr wrote on 31 okt 2004 in microsoft.public.inetserver.asp.general: What is the difference in the result?
Please quote where you are responding on.
This is not email, but usenet.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup) This discussion thread is closed Replies have been disabled for this discussion. Similar topics
reply
views
Thread by yulyos |
last post: by
|
6 posts
views
Thread by Penguin |
last post: by
|
2 posts
views
Thread by Marcos Jose Setim |
last post: by
|
4 posts
views
Thread by Fuzzydave |
last post: by
|
5 posts
views
Thread by ibiza |
last post: by
|
6 posts
views
Thread by dkirkdrei |
last post: by
| | |
reply
views
Thread by Edwin.Madari |
last post: by
| | | | | | | | | | |