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

Undocumented rounding algorithm

I am upgrading an MS Access 97 application which uses the format
function to round decimal numbers to two places

e.g. format(dblValue, "standard")

Having done an initial study of this function I can see no obvious
pattern in how it does rounding, it is certainly not bankers rounding.

I need to replicate the rounding algorithm used in the new application
so that the data will be consistent, so if anyone knows the rounding
algorithm used in the Access 97 format function it will save me a lot
of time.

I believe that Microsoft changed the rounding algorithm in Access 2000
so the algorithm I need is the one in Access 97.

Nov 13 '05 #1
6 3384
format does not do any rounding. If you *really* want to round, then
use the ROUND function.

Nov 13 '05 #2
you can find a bunch of rounding algorithms at
http://www.xbeat.net/vbspeed/c_Round.htm
most are adaptable for Access 97.

Nov 13 '05 #3
pi********@hotmail.com wrote:
format does not do any rounding. If you *really* want to round, then
use the ROUND function.


Actually Format() does round.

?Format(123.45678,"#.00")
123.46

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #4
Rick Brandt wrote:
pi********@hotmail.com wrote:
format does not do any rounding. If you *really* want to round, then
use the ROUND function.


Actually Format() does round.

?Format(123.45678,"#.00")
123.46


Sorry, should have been...

?Format(123.454,"0.0#")
123.45

?Format(123.456,"0.0#")
123.46

It actually performs the "non-bankers rounding" where the 5 always rounds
up.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #5
The problem is that in Access 97 the 5 does not always round up e.g.

format("3.155","0.00") = 3.15 (down )
format("3.135","0.00") = 3.13 (down)
format("3.335","0.00") = 3.34 (up)
format("3.735","0.00") = 3.73 (down)

These are only a few of the many anomolies to be found. The first digit
after the decimal point seems to have some effect but it is not obvious
what it is.
I am upgrading an Access 97 application to Access 2003 but the new
application has to be able calculate identical amounts as the Access 97
app.

Nov 13 '05 #6
On 10 Jul 2005 01:34:41 -0700, "DaveK" <fo*************@gmail.com> wrote:
The problem is that in Access 97 the 5 does not always round up e.g.

format("3.155","0.00") = 3.15 (down )
format("3.135","0.00") = 3.13 (down)
format("3.335","0.00") = 3.34 (up)
format("3.735","0.00") = 3.73 (down)

These are only a few of the many anomolies to be found. The first digit
after the decimal point seems to have some effect but it is not obvious
what it is.
I am upgrading an Access 97 application to Access 2003 but the new
application has to be able calculate identical amounts as the Access 97
app.


If you're using fixed point numbers (e.g. Currency), the behavior should be
consistent. If you're using Double or Float, then good luck - you'll need it.
Double and Float are approximate types, and anything you do to them is
approximate. Just because a double or float is supposedly equal to, say,
3.155 doesn't mean it is, or that the number can even be precisely represented
as a binary fraction (which is how these numbers are stored).
Nov 13 '05 #7

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

Similar topics

17
by: Gordon Williams | last post by:
Hi, I have to lists that I need to find the common numbers (2nd rounded to nearest integral) and I am wondering if there is a more efficient way of doing it. >>> a= >>> b= >>> ...
7
by: Steven T. Hatton | last post by:
I'm surprised I haven't hit this situation till now, but I don't believe I've had to deal with it before. I have a function that sets the components of a point class (QPoint from Qt). It takes...
13
by: dhildebrandt | last post by:
I have a query that uses the Round function to change decimals into whole numbers. For 4 years straight the thing has always rounded the numbers in exactly the same way so that whenever I update...
0
by: Darrell Sparti, MCSD | last post by:
There have been many postings about this subject on this newsgroup. Unfortunately, they're incorrect. You can't just cast a value in C# and have it work for all ASCII characters. Nor can you use...
13
by: Shirsoft | last post by:
I have a 32 bit intel and 64 bit AMD machine. There is a rounding error in the 8th digit. Unfortunately because of the algorithm we use, the errors percolate into higher digits. C++ code is...
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
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: 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
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:
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.