BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"Banking method of rounding"
, by vic-e-babes
Some people think that the way that Blitz rounds floats of exactly
n.5 when assigning them to integers is a bug. I don't think it is.
Code
The following assigns consecutive floats that are increase by 0.5 in a loop to an integer, and prints the results. If you went to school as long ago as I did, you would expect numbers ending in exactly n.5 to be rounded up. However, Blitz appears to use the banking method, which is designed to be more accurate. Floats that end in exactly .5 are always rounded to the nearest EVEN number. This is because if you always round up, and you are using lots of figures - then the final figure can be out by quite a margin. Rounding to the nearest EVEN number however, tends to balance things out - which is why it is used in banks. This is my opinion, but wouldn't know who to ask to confirm it/ However, the results shown below should show this. JazzieB was the one who showed me this code For i# = 0 To 10 Step .5 j = i Print i+" = "+j Next Results are... 0 0 1 2 2 2 3 4 4 4 5 6 6 6 7 8 8 8 9 10 10
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations