Banker's rounding method (rounding)

Article directory

Banker's rounding method:

A common calculation method in life is rounding, but the banker's rounding method is rounding. If there is a non-0 number after five, it will be forwarded directly. If there is no number, it will also depend on whether the previous digit is an even number or an odd number. Even numbers are discarded and odd numbers are rounded up.

Summed up in one sentence: consider rounding to five. If the number after five is not zero, then round it by one. If the number after five is zero, look at the odd or even number. If the number before five is even, it should be discarded. If the number before five is odd, round it by one.

As shown in the figure:
Insert image description here
In fact, most programming languages ​​use the banker's rounding method when calculating floating point numbers or retaining decimal places, for example: Java

Even if you change the process, you can't change the outcome

Guess you like

Origin blog.csdn.net/weixin_45377770/article/details/109810795