473,320 Members | 2,164 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,320 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 35890
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.