473,395 Members | 1,762 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,395 software developers and data experts.

Rounding Up

Is there a way to make your numbers always round up. Ex:
if the number is 0.0341 it will round to 0.035

Brent
Jul 19 '05 #1
4 10609
If you always want it at the thousandths, you could say:

<%
function roundUp(n)
if clng(n*10000) = 10 * clng(n*1000) then
n = formatnumber(n, 3)
else
n = formatnumber(n + 0.0005, 3)
end if
roundup = n
end function

response.write "<br>" & roundUp(0.0341)
response.write "<br>" & roundUp(0.03409)
response.write "<br>" & roundUp(0.0340)
response.write "<br>" & roundUp(0.0359)

%>

"Brent Bortnick" <br***@hitechseals.com> wrote in message
news:47****************************@phx.gbl...
Is there a way to make your numbers always round up. Ex:
if the number is 0.0341 it will round to 0.035

Brent

Jul 19 '05 #2
"Brent Bortnick" wrote:

Is there a way to make your numbers always round up. Ex:
if the number is 0.0341 it will round to 0.035


JScript:
val = Math.ceil(1000*val)/1000
http://msdn.microsoft.com/library/en...6jsmthceil.asp

VBScript (depends on how you want to handle negative numbers):
If val*1000 <> Fix(val*1000) Then val = Fix(val*1000+1)/1000
If val*1000 <> Int(val*1000) Then val = Int(val*1000+1)/1000
http://msdn.microsoft.com/library/en...l/vsfctint.asp

Of course, both methods introduce you to the problem of representing
decimals with binary digits. See this for details:
http://support.microsoft.com/default...;EN-US;q244699

You can opt for string representations of those numbers with either of the
following.

JScript:
http://msdn.microsoft.com/library/en...mthtofixed.asp

vbscript:
http://msdn.microsoft.com/library/en...rmatNumber.asp
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 19 '05 #3
Aaron Bertrand - MVP wrote on 02 jul 2003 in
microsoft.public.inetserver.asp.general:
If you always want it at the thousandths, you could say:

<%
function roundUp(n)
if clng(n*10000) = 10 * clng(n*1000) then
n = formatnumber(n, 3)
else
n = formatnumber(n + 0.0005, 3)
end if
roundup = n
end function

response.write "<br>" & roundUp(0.0341)
response.write "<br>" & roundUp(0.03409)
response.write "<br>" & roundUp(0.0340)
response.write "<br>" & roundUp(0.0359)

%>


Or:

function roundUp(n)
n = int(n*1000+0.999999)/1000
roundup = formatnumber(n, 3)
end function
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #4
"Aaron Bertrand - MVP" wrote:

if clng(n*10000) = 10 * clng(n*1000) then
n = formatnumber(n, 3)
else
n = formatnumber(n + 0.0005, 3)
end if


CLng uses Banker's rounding, so it's wise to avoid in an ALWAYS up/down
scenario. Compare the following with this function:

roundUp(0.00105) --> 0.001
roundUp(0.00106) --> 0.002

http://support.microsoft.com/default...;EN-US;Q196652
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Norvin Laudon | last post by:
Hi, Can somebody explain the following, from the MSDN documentation for the "System.Convert.ToInt32(double)" function <quote> Return Value value rounded to the nearest 32-bit signed...
4
by: spebola | last post by:
I am using vb.net 2003 professional and I get the following results when using the round method: dim Amount as decimal = 180.255 Amount = Amount.Round(Amount, 2) Amount now contains 180.25. ...
8
by: Zorpiedoman | last post by:
Howcome: Dim D as decimal = .5D msgbox d.Round(D, 0) this returns "0" Now when I went to school .5 rounds UP to 1 not DOWN to zero?????!!! Documentation says this, but what the heck are...
2
by: Jiri Nemec | last post by:
Hello all, I have got one table with rounding values, table contains prices and round types. id price_from price_to rounding 1 0 1500 0.1 2 1500 ...
11
by: cj | last post by:
Lets assume all calculations are done with decimal data types so things are as precise as possible. When it comes to the final rounding to cut a check to pay dividends for example in VB rounding...
18
by: jdrott1 | last post by:
i'm trying to round my currency string to end in 9. it's for a pricing application. this is the function i'm using to get the item in currency: FormatCurrency(BoxCost, , , , TriState.True) if...
5
by: Spoon | last post by:
Hello everyone, I don't understand how the lrint() function works. long lrint(double x); The function returns the nearest long integer to x, consistent with the current rounding mode. It...
206
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
20
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
30
by: bdsatish | last post by:
The built-in function round( ) will always "round up", that is 1.5 is rounded to 2.0 and 2.5 is rounded to 3.0. If I want to round to the nearest even, that is my_round(1.5) = 2 # As...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.