Post Reply 
(12C) Banker's Rounding Method
11-27-2018, 06:42 PM (This post was last modified: 12-08-2018 08:46 PM by Albert Chan.)
Post: #2
RE: (12C) Banker's Rounding Method
I think banker's rounding method apply to non-integers too (edge case round-to-even).

For banker's rounding to nearest integer, this is shorter

Code:
01 .
02 5
03 X≤Y ; handle negative input
04 CHS
05 -
06 FRAC
07 x=0 ; edge case ?
08 GTO 12
09 Lst-X
10 INTG
11 GTO 00
12 Lst-X ; edge round-to-even
13 2
14 ÷
15 INTG
16 2
17 ×
18 GTO 00

Example:
1233.5 R/S ==> 1234
1233.9 R/S ==> 1234
1234.5 R/S ==> 1234

1233.49 R/S ==> 1233
1234.51 R/S ==> 1235

Updated: code numbering start from 1, instead of 0
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (12C) Banker's Rounding Method - Albert Chan - 11-27-2018 06:42 PM



User(s) browsing this thread: 1 Guest(s)