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

1.625 should round to 1.63... not 1.62... RIGHT?

n8kindt
221 100+
using access 2007

here's the code from the builder i'm working with

ExpectedTax: ([TaxPercent]*([Subtotal]-[ProductPurchased]))+(2*[ProductPurchased]*[TaxPercent])

when i was trying this out, one of the results i got was 1.625 ... i need this (and the underlying data) to be rounded to 1.63 ... unfortunately when i tried the round function

ExpectedTax: Round(([TaxPercent]*([Subtotal]-[ProductPurchased]))+(2*[ProductPurchased]*[TaxPercent]),2)

it displays 1.62 ... why doesn't it round up?? i also tried changing to to currency but that does no good b/c the underlying data still displays 1.625 and i need that figure to be rounded at some point. but whatever i do it rounds down.
can anyone help??
Mar 13 '08 #1
7 7473
Scott Price
1,384 Expert 1GB
The Round function in VBA behaves a little oddly... It utilizes what is called round-to-even or Bankers Rounding. What that means is that it will round to the nearest even number. Rather a nice M$ trick, I'd say ;-)

One way to get around this and make it round as you wish is to add 0.000000001 to the end of your 1.625 figure. This will make it round to the 1.63 figure you want. If adding this will significantly affect your calculations (which I doubt as you are calculating using a rounded number to begin with), you will need to write a special function to handle the rounding.

Regards,
Scott
Mar 14 '08 #2
Scott Price
1,384 Expert 1GB
I should clarify my statement... When the decimal number ends with 5 it rounds to the nearest even number. Thus Round(1.625,2) rounds to 1.62, however Round(1.635,2) will result in 1.64.

Adding the 0.00000001 figure makes the decimal end in 1 instead of 5, which makes the rounding work in the traditional way.

Regards,
Scott
Mar 14 '08 #3
n8kindt
221 100+
The Round function in VBA behaves a little oddly... It utilizes what is called round-to-even or Bankers Rounding. What that means is that it will round to the nearest even number. Rather a nice M$ trick, I'd say ;-)

One way to get around this and make it round as you wish is to add 0.000000001 to the end of your 1.625 figure. This will make it round to the 1.63 figure you want. If adding this will significantly affect your calculations (which I doubt as you are calculating using a rounded number to begin with), you will need to write a special function to handle the rounding.

Regards,
Scott
thanks for the explanation, scott. i'll give it a try!
Mar 14 '08 #4
n8kindt
221 100+
I should clarify my statement... When the decimal number ends with 5 it rounds to the nearest even number. Thus Round(1.625,2) rounds to 1.62, however Round(1.635,2) will result in 1.64.

Adding the 0.00000001 figure makes the decimal end in 1 instead of 5, which makes the rounding work in the traditional way.

Regards,
Scott
it seems to have done the trick. thanks so much! i read something about adding the .000001 somewhere else but it didnt make sense without your explanation!

cheers,
nate
Mar 14 '08 #5
Scott Price
1,384 Expert 1GB
Not a problem, hope you get it working correctly :-)

Regards,
Scott
Mar 14 '08 #6
Scott Price
1,384 Expert 1GB
An interesting article for further reading for you or anyone who stumbles onto this article in the future: http://support.microsoft.com/kb/196652/EN-US/.

The point made about Banker's Rounding and the logic behind it is that consistently rounding decimals ending in 5 up will introduce a bias into your calculations as you add more rounded numbers. In other words, it will artificially inflate your end totals after a certain number of calculations. Banker's Rounding therefore attempts to flatten out this bias curve by introducing a separate rounding algorithm that will keep some of this artificial inflation from happening.

Maybe I should apologize to Bill for my slightly sarcastic comment earlier about M$? :-)

Regards,
Scott
Mar 14 '08 #7
Try to do it this way.. simple.. design view of your table, your number field, format -> decimal and change scale from 0 to 2 and your will be okay
Oct 21 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Russell E. Owen | last post by:
I realize this probably a stupid question, but...is it safe to round to the nearest integer by using int(round(val))? I suspect it is fine, but wanted to be sure that weird floating point...
9
by: joeandtel | last post by:
If I have a value that is 53.123499999, how can I round it to 53.12?
2
by: Matias Silva | last post by:
Can anybody tell me why I am getting rounding errors using the ROUND function. 3.7125 rounds to 3.70 when I use the following: TRUNCATE(ROUND(units_pay_amount * fees_amount, 2),2))) The correct...
14
by: Nils Grimsmo | last post by:
Why did round() change in Python 2.4? $ python2.3 Python 2.3.5 (#2, Jun 19 2005, 13:28:00) on linux2 >>> round(0.0225, 3) 0.023 >>> "%.3f" % round(0.0225, 3) '0.023' >>>
4
by: hamster | last post by:
I don't know how to write the code for round command? For example if more than .5 then round up,if less than .5 round down such as 4.3 round to 4.0 and 5.5 round to 6.0
21
by: Karl O. Pinc | last post by:
FYI, It'd be nice if the error message from a REFERENCES constraint mentioned the column name into which the bad data was attempted to be inserted. In PostgreSQL 7.3: sandbox=> insert into...
36
by: Phat G5 (G3) | last post by:
Has anyone found a reliable way to force JS to round to a specific number of places? Every time I try I get different results. For example, I'd need to round 3.4589 to 2 places. What is the most...
2
by: Radek Cerny | last post by:
Hopefully I'm just missing something obvious, but this method (or more likely the CLR/complier) has a bug where I can not use the overloaded version: Round( double value, int digits ) It always...
3
by: Altman | last post by:
OK I was having rounding problems before and I didn't realize that their was a third parameter in the round function that would tell it if it a 5 to round up. I thought adding this would fix the...
4
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.