473,389 Members | 1,142 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,389 software developers and data experts.

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 35919
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: yulyos | last post by:
Hi, Round Number Function You can download a small example: Watch and copy examples of Source Code in VB.NET yulyos4vbnet@yahoo.com http://www.geocities.com/yulyos4vbnet Have a nice day
6
by: Penguin | last post by:
At some long ago time Steve Jorgensen answered thus: Subject: Re: How can I round a time? Newsgroups: comp.databases.ms-access Date: 1998/12/11 Access represents a date internally as a double...
2
by: Marcos Jose Setim | last post by:
Hello, I need to round one number in language C, but I did not obtain. I already tried to use the: #include <math.h> ceil(value); But it's shown one error:
4
by: Fuzzydave | last post by:
I have been using a round command in a few places to round a value to zero decimal places using the following format, round('+value+', 0) but this consistantly returns the rounded result of...
5
by: ibiza | last post by:
Hi all, I'd need a function that would rounds values like : d = roundTo(64.2, 0.25) ' returns 64.25 d = roundTo(64.2, 10) ' returns 64 d = roundTo(64.2, 100) ' returns 100 well, that rounds...
6
by: dkirkdrei | last post by:
I am looking for a way to round a number (which will be displayed as a dollar amount) to the nearest nickel. Using the php round function only allows you to control the number of decimal places in...
1
by: dhutton | last post by:
Hello - Question... What would be the best way to round a number off and change it to currency with the below statement? SELECT Cycle AS BillCycle, SUM(PrevBillAmt) - SUM(Payment) +...
19
by: muddasirmunir | last post by:
can any body tell me how to round numbers in in exactly two decimal places i had use a function round(text1.text,2) but whenever there is zere(0) at the end it does not show it for eg for round...
0
by: Edwin.Madari | last post by:
>>round(76.1, -2) 100.0 80.0 76.0 builtin function round, will work for you...... Help on built-in function round in module __builtin__: round(...) round(number) -floating point number
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.