Rounding [banker algorithm]

Source: Internet
Author: User

For the concept of "rounding", I believe everyone is familiar with, because the primary three or four grade has been contacted, the conventional algorithm here withheld.
But for the banker algorithm, perhaps a lot of people are unfamiliar. Recent study encountered, but also understand the algorithm can be summed up as "four homes six into five to take the pair." That is: (assuming rounding of the decimal part),
The part to be rounded is exactly 0.5000, so you need to look at the parity of the previous one, the odd number, the even.
Give a few examples to describe, for example:
1.5000-2
2.5000-2
3.5000-4
4.5000-4
...... ......
So, why did you do that?

By regular rounding algorithm
...... ......
[0.5,1.5] = 1
[1.5,2.5] = 2
[2.5,3.5] = 3
[3.5,4.5] = 4
[4.5,5.5] = 5
[5.5,6.5] = 6
...... ......
Left closed right meeting let exactly for n+0.5 value all into, and left open right closed then all shed, so, general rounding will
The tendency to make a value to one end. Data too much, will form a relatively large deviation, so, someone proposed banker algorithm.
Banker algorithm
...... ......
(0.5,1.5) = 1
[1.5,2.5] = 2
(2.5,3.5) = 3
[3.5,4.5] = 4
(4.5,5.5) = 5
[5.5,6.5] = 6
...... ......
In this way, the values are separated by one n+0.5, so that the values tend to be balanced.
Overall, there is no big deviation in the data.

Rounding [banker algorithm]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.