 |
| ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 19th, 2003, 10:08 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Is there a round vbscript function that works?
Is there a round function that will round 4.5 to 5? Seems we have CInt() which returns even numbers only as well as Round() which also returns even numbers. I'm in desperate need of a function that returns the next higher value if argument is n.5. Thanks
|
|

August 19th, 2003, 04:02 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Well this is very interesting. I just did a test. I couldn't believe that the result of rounding 4.5 could possibly be 4 so I tried it out. I found this using Math.Round():
2.49999999999999 -> 2
2.50000000000000 -> 2
2.50000000000001 -> 3
3.49999999999999 -> 3
3.50000000000000 -> 4
3.50000000000001 -> 4
4.49999999999999 -> 4
4.50000000000000 -> 4
4.50000000000001 -> 5
5.49999999999999 -> 5
5.50000000000000 -> 6
5.50000000000001 -> 6
(14 decimal places)
This is pretty interesting. It does seem that the rounding functionality is preferential to odd numbers. Did I miss something in primary school??
Can anyone shed any light on this?
Peter
|
|

August 19th, 2003, 04:16 PM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Just out of curiosity what version of .Net Framework did you test this on? I wonder if Microsoft is aware of this?
|
|

August 19th, 2003, 05:10 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
I ran this on both framework 1.0.3705 and 1.1.4322 and got the exact same results. :( This can't be good.
|
|

August 19th, 2003, 08:48 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
I don't get it, 4.5 rounds to 4,
5.5 to 6,
as they should.....shouldn't they????
Your results show a preference for even numbers not odd.
At school I learnt to round to the even.
Sorry if I messed the point.
Rod
======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
|
|

August 20th, 2003, 01:51 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This type of rounding is called "Banker's Rounding". If you do a search using google.com (or your favourite search engine) you will see why it is used.
You will also find generic formulas for solving the problem you are running into.
Cheers
Ken
www.adOpenStatic.com
|
|

August 20th, 2003, 03:21 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Seems like the discussion has moved to this thread - I wish people wouldn't post the same thing on multiple forums...
Anyway, there is no mention of bankers rounding in MSDN, but I found this enlightening quote under the topic of "Conversion, Rounding and Truncation"
Quote:
quote:
Although the Round function is useful for returning a number with a specified number of decimal places, you cannot always predict how it will round when the rounding digit is a 5. How VBA rounds a number depends on the internal binary representation of that number. If you want to write a rounding function that will round decimal values according to predictable rules, you should write your own.
|
rgds
Phil
|
|

August 20th, 2003, 11:14 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I always learned in school the following
.0 to .49999999... rounded down
.5 to .99999999... rounded up
I never heard of the bankers rounding or rounding to the even. Does not mean they do not exist because they obviously do, I have just not heard, nor learned of them till now.
Chris
|
|

August 20th, 2003, 11:23 AM
|
|
Registered User
|
|
Join Date: Aug 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Direct from the April 2003 MSDN documentation....
"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."
|
|
 |