Alipay+ DocsAlipay+ Docs

Banker's rounding

The Banker's Rounding is a midpoint rounding scheme, in which numbers equidistant from the two nearest integers are rounded to the nearest even integer. Banker's rounding method is a floating-point rounding algorithm specified by the IEEE 754 standard, and is applied in most programming software.

This topic introduces how to round a number with the Banker's rounding method and why this method is used by Alipay+.

How to round numbers with banker's rounding

With the banker's rounding, when the number to be rounded (the rounding digit) is followed by 1, 2, 3, and 4, round the number down; when followed by 6, 7, 8, and 9, round the number up. However, for numbers followed by 5, the rounding direction is determined according to the number after 5:

  • When there is a number after 5, round up.
  • When there is no number after 5:
    • If it is an odd number before 5, round up.
    • If it is an even number before 5, round down.

The following table lists the examples for all the previously mentioned scenarios:

Number following the rounding digit

Rounding direction

Example

0 - 4

Rounded down

2.121->2.12

5 (being the last digit)

The rounding digit is an even number.

Rounded down

2.125->2.12

The rounding digit is an odd number.

Rounded up

2.135->2.14

5 (not being the last digit)

Rounded up

2.1351->2.14

6 - 9

Rounded up

2.127->2.13

Why Alipay+ adopts banker's rounding

Banker's rounding is more accurate and fairer than standard rounding. The following table uses bank interests as an example:

Interest

Standard rounding results

Banker's rounding results

Result

Deviation

Result

Deviation

0.005

0.01

0.005

0

-0.005

0.015

0.02

0.005

0.02

0.005

0.025

0.03

0.005

0.02

-0.005

0.035

0.04

0.005

0.04

0.005

0.045

0.05

0.005

0.04

-0.005

Total

0.125

Total

0.15

Total

0.025

Total

0.12

Total

0.005

It can be seen that the deviation of the banker's rounding result is less than the deviation of standard rounding. When the rounding digit is 5, the deviation of the standard rounding is 0.025, whereas that of the banker's rounding is only 0.005.