Banker's Rounding - how to round currency values properly in your program · Заметки

Век живи, век учись.

Banker's Rounding - Google Checkout uses banker's rounding for all financial calculations. Banker's rounding is the same as the traditional method of rounding numbers with one exception. In banker's rounding, if the number to be rounded is followed by a five and no additional nonzero digits, the number is rounded to the nearest even number. The following examples demonstrate the expected behavior in banker's rounding:

  • 12.435 would be rounded up to 12.44. The number to be rounded (3) is rounded to the nearest even digit (4).
  • 12.445 would be rounded down to 12.44. The number to be rounded (4) is not rounded because it is an even digit.
  • 12.44501 would be rounded up to 12.45. The number to be rounded (4) is followed by a five and by additional nonzero digits.



Comments:

No Comments for this post yet...

Leave a comment:

Your email address will not be displayed on this site.
Your URL will not be displayed on this site. Comments containing URL's of non-personal pages may be removed.
Confirmation Code:
Human Confirmation Code (Captcha)

HTML tags and "<", ">" symbols are not allowed. Links will not be converted to hyperlinks. Any commercials are removed and reported as abuse.

Archives

                                                                                                                                                                                                                                                                   


© Sergey A. Galin, 1998-2021 sageshome.net/blog/