473,666 Members | 2,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3411
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********@hotm ail.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.456 78,"#.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********@hotm ail.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.456 78,"#.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
2772
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= >>> (l,round(m))]
7
4096
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 integer arguments for the components. I am calculating the values using transcendental functions sin and cos which return floating point type values. (The compiler claims they are double though I expected float in, float out.) I guess I have some...
13
1719
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 my graphs, the percentages for the historical data are always exactly what they were the last time I ran the query. Now, for the first time my percentages are all just slightly off and I have not changed the query. The only thing I can think of...
0
737
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 the ASCII encoding as some have suggested. The undocumented truth is, Microsoft uses the Western European encoding in these functions. If you don't believe me, use 137 in your VB Chr function then compare the C# output if you just cast it or...
13
6180
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 ------------------ b += (float)(mode *val); On 32 bit(intel , vs 2003, C++), some watch variables are
206
13229
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) It then updates the value with numberOfPrecisions after the decimal
20
4989
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
29563
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 expected my_round(2.5) = 2 # Not 3, which is an odd num I'm interested in rounding numbers of the form "x.5" depending upon whether x is odd or even. Any idea about how to implement it ?
0
8348
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8779
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7376
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.