469,366 Members | 2,198 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

Round up Number

D
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!
Jul 19 '05 #1
12 34426
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!

Jul 19 '05 #2
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!

Jul 19 '05 #3
D
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!
Jul 19 '05 #4
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)

Jul 19 '05 #5
Coz
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)

Jul 21 '05 #6
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)

Jul 21 '05 #7
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!

Jul 21 '05 #8
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)

Jul 21 '05 #9
Function RoundUp(num1)
RoundUp = 0
If IsNumeric(num1) Then
RoundUp = FormatNumber(CDbl(num1) + .5,0)
End If
End Function
'dlbjr
'Pleading sagacious indoctrination!
Jul 21 '05 #10
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)

Jul 21 '05 #11
What is the difference in the result?

'dlbjr
'Pleading sagacious indoctrination!
Jul 21 '05 #12
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)

Jul 21 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by yulyos | last post: by
2 posts views Thread by Marcos Jose Setim | last post: by
4 posts views Thread by Fuzzydave | last post: by
6 posts views Thread by dkirkdrei | last post: by
reply views Thread by Edwin.Madari | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.