Home > Archive > ASP > October 2004 > Round up Number
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| 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!
| |
| Ray Costanzo [MVP] 2004-10-18, 3:55 am |
| 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.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
| |
| Ken Schaefer 2004-10-18, 3:55 am |
| 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.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!
| |
| Evertjan. 2004-10-18, 3:55 am |
| 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...
[color=darkred]
> 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." <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)
>
| |
| Evertjan. 2004-10-23, 8:55 am |
| 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)
| |
|
| 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.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
| |
| Evertjan. 2004-10-31, 8:55 am |
| 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!
| |
| Evertjan. 2004-10-31, 3:55 pm |
| 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!
| |
| Evertjan. 2004-10-31, 3:55 pm |
| 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)
|
|
|
|
|