473,770 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Rounding, are we MAD????

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 they thinking??? I just don't
get it. This is insane!?!?!?!! (or maybe I am)

"When d is exactly halfway between two rounded values, the result is the
rounded value that has an even digit in the far right decimal position. For
example, when rounded to two decimals, the value 2.345 becomes 2.34 and the
value 2.355 becomes 2.36. This process is known as rounding toward even, or
rounding to nearest."

--
--Zorpie
Nov 21 '05 #1
8 2086
It's actually the BANKERS fault:

"The behavior of this method follows IEEE Standard 754, section 4. This kind
of rounding is sometimes called rounding to nearest, or banker's rounding."

Anyway, the reason this all came up was because we were doing some
compairson between some old ACCESS reports and some new reports we are
designing in VB.NET. In ACCESS, when a value of .05 was FORMATTED "0,0" it
returned 0.1, which goes along with my third grade math thinking. When we
changed the formula to use the ROUND function, it returned 0. An odd and
obscure little gotcha that we just stumbled across, I guess.

Oh well, that was fun...!
--
--Zorpie
"Kerry Moorman" wrote:
Zorpie,

I suspect that Simple Math, Grade 3 does not comform to IEEE Standard 754
with respect to rounding because IEEE Standard 754 is too complex for third
graders.

If you want to always use the type of rounding you learned in third grade,
then Math.Ceiling might be for you.

Kerry Moorman
"Zorpiedoma n" wrote:
Ok, then why does IEEE Standard 754 not comply to Simple Math, grade 3? I
really must be going mad. All my life I have been taught that .5 rounds to
1. Microsoft ACCESS will round .5 and get 1. Sheesh.
--
--Zorpie
"Kerry Moorman" wrote:
Zorpie,

Rounding in .Net at least claims to follow IEEE Standard 754. Therefore,
several different ways to round are provided:

Round
Ceiling
Floor

In addition, VB provides several keywords that apply to rounding in one way
or another:

INT
FIX
CINT

You just need to pick a method or keyword that works the way you need it to
for a particular application.

Kerry Moorman

"Zorpiedoma n" wrote:

> 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 they thinking??? I just don't
> get it. This is insane!?!?!?!! (or maybe I am)
>
> "When d is exactly halfway between two rounded values, the result is the
> rounded value that has an even digit in the far right decimal position. For
> example, when rounded to two decimals, the value 2.345 becomes 2.34 and the
> value 2.355 becomes 2.36. This process is known as rounding toward even, or
> rounding to nearest."
>
> --
> --Zorpie

Nov 21 '05 #2
Zorpie,

Rounding in .Net at least claims to follow IEEE Standard 754. Therefore,
several different ways to round are provided:

Round
Ceiling
Floor

In addition, VB provides several keywords that apply to rounding in one way
or another:

INT
FIX
CINT

You just need to pick a method or keyword that works the way you need it to
for a particular application.

Kerry Moorman

"Zorpiedoma n" wrote:
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 they thinking??? I just don't
get it. This is insane!?!?!?!! (or maybe I am)

"When d is exactly halfway between two rounded values, the result is the
rounded value that has an even digit in the far right decimal position. For
example, when rounded to two decimals, the value 2.345 becomes 2.34 and the
value 2.355 becomes 2.36. This process is known as rounding toward even, or
rounding to nearest."

--
--Zorpie

Nov 21 '05 #3
Zorpie,

I suspect that Simple Math, Grade 3 does not comform to IEEE Standard 754
with respect to rounding because IEEE Standard 754 is too complex for third
graders.

If you want to always use the type of rounding you learned in third grade,
then Math.Ceiling might be for you.

Kerry Moorman
"Zorpiedoma n" wrote:
Ok, then why does IEEE Standard 754 not comply to Simple Math, grade 3? I
really must be going mad. All my life I have been taught that .5 rounds to
1. Microsoft ACCESS will round .5 and get 1. Sheesh.
--
--Zorpie
"Kerry Moorman" wrote:
Zorpie,

Rounding in .Net at least claims to follow IEEE Standard 754. Therefore,
several different ways to round are provided:

Round
Ceiling
Floor

In addition, VB provides several keywords that apply to rounding in one way
or another:

INT
FIX
CINT

You just need to pick a method or keyword that works the way you need it to
for a particular application.

Kerry Moorman

"Zorpiedoma n" wrote:
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 they thinking??? I just don't
get it. This is insane!?!?!?!! (or maybe I am)

"When d is exactly halfway between two rounded values, the result is the
rounded value that has an even digit in the far right decimal position. For
example, when rounded to two decimals, the value 2.345 becomes 2.34 and the
value 2.355 becomes 2.36. This process is known as rounding toward even, or
rounding to nearest."

--
--Zorpie

Nov 21 '05 #4
"Zorpiedoma n" <no*********@be atles.com> wrote in message
news:B5******** *************** ***********@mic rosoft.com...
It's actually the BANKERS fault:

"The behavior of this method follows IEEE Standard 754, section 4. This
kind of rounding is sometimes called rounding to nearest, or banker's
rounding."


Funny. When I learned it in grade 9 it had nothing to do with banking or
engineering, it was just math (yes grade 9 math was more complicated than
grade 3 math, just like calculus is more complicated than grade 3 math). In
university I learned why engineers had better make sure to do rounding this
way, coding it themselves if the hardware didn't do it for them. From your
posting I learn that bankers find it equally important.

But it's still not the fault of bankers or engineers or mathematicians. If
you believe in Intelligent Design then it's God's fault. As for your
trouble with grade 9 math, whose fault is that? I do agree with one of your
observations though. When Microsoft graduated from grade 3 to grade 9, it
was a breaking change.

Nov 21 '05 #5
Zorpiedoman,

This is one of the changes in VS 2005, it allows more kind of roundings.

Cor
Nov 21 '05 #6
so, nobody answered the question "is this rounding expected and declared to
produce 0 from .5 ?". do IEEE rules commands this?

"Zorpiedoma n" <no*********@be atles.com> wrote in message
news:63******** *************** ***********@mic rosoft.com...
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 they thinking??? I just
don't
get it. This is insane!?!?!?!! (or maybe I am)

"When d is exactly halfway between two rounded values, the result is the
rounded value that has an even digit in the far right decimal position.
For
example, when rounded to two decimals, the value 2.345 becomes 2.34 and
the
value 2.355 becomes 2.36. This process is known as rounding toward even,
or
rounding to nearest."

--
--Zorpie

Nov 21 '05 #7
Gjuro,
produce 0 from .5 ?". do IEEE rules commands this?


Yes as already probably thousand times answered in these newsgroups,

However in my opinon should any good develloper be able to set the rounding
in the style he wishes by creating the code for that himself, if it is not
provided as a standard.

Cor
Nov 21 '05 #8
Back in the day we had a real simple solutin for this:

i = INT(x + 0.5)

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Gjuro,
produce 0 from .5 ?". do IEEE rules commands this?


Yes as already probably thousand times answered in these newsgroups,

However in my opinon should any good develloper be able to set the
rounding in the style he wishes by creating the code for that himself, if
it is not provided as a standard.

Cor

Nov 21 '05 #9

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

Similar topics

3
6741
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 integer. If value is halfway between two whole numbers, the even number is returned; that is, 4.5 is
4
7833
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. I need it to contain 180.26. Any ideas?
2
2642
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 5000 1 3 5000 15000 10 4 15000 0 100
11
6657
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 seems to be done like this 3.435 = 3.44 3.445 = 3.44 Dim decNbr1 As Decimal
18
2231
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 an item is 41.87 i want the application to bring it up to 41.89 if an item is 41.84 i want the application to round down to 41.79 does anyone know how i could do this?
5
8013
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 raises an invalid floating-point exception if the magnitude of the rounded value is too large to represent. And it raises an inexact floating-point exception if the return value does not
206
13308
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
5014
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
29686
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
9617
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9453
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
10254
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...
1
10036
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
9904
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
8929
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...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.