Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
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
 
Old August 19th, 2003, 10:08 AM
Authorized User
 
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old August 19th, 2003, 04:02 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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

 
Old August 19th, 2003, 04:16 PM
Authorized User
 
Join Date: Jul 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just out of curiosity what version of .Net Framework did you test this on? I wonder if Microsoft is aware of this?

 
Old August 19th, 2003, 05:10 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I ran this on both framework 1.0.3705 and 1.1.4322 and got the exact same results. :( This can't be good.

 
Old August 19th, 2003, 08:48 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

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.
======================================
 
Old August 20th, 2003, 01:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old August 20th, 2003, 03:21 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old August 20th, 2003, 11:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old August 20th, 2003, 11:23 AM
Registered User
 
Join Date: Aug 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Canuck
Default

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."






Similar Threads
Thread Thread Starter Forum Replies Last Post
Round Function in Derived column transformation loveyaseen BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 0 October 31st, 2007 08:19 AM
Calling VBScript Function from javascript arnabghosh Classic ASP Professional 1 July 13th, 2007 08:32 AM
Problem with Round Function darrenb Access 3 May 22nd, 2007 05:45 PM
Decimal place problem...ROUND function! kuku SQL Server 2000 9 July 9th, 2005 05:50 PM
round function help mohiddin52 Access 2 October 21st, 2004 07:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.