Swiss and Argentinian currency fourth decimal digi

2019-03-27 08:52发布

When rounding amounts of currency using the algorithm for Swiss Francs, the second and third decimal digits are considered. If less than 26, they are rounded down to 0; else if less than 76, rounded down to 5; else the whole value is rounded up.

20.125  =>  20.10
20.143  =>  20.15
20.179  =>  20.20

What happens when the amount to be rounded has a greater decimal precision? Are all decimal digits after the third simply ignored (value is truncated), or is the value first rounded in some other way to three decimal digits first? As an example, consider truncation versus a "Math.round()" approach (less than 0.5 rounds down, else round up):

Truncation                      |  "Math.round"
=================================================================
Start        3 d.p.    Rounded  |  Start        3 d.p.    Rounded
=================================================================
20.1259  ->  20.125  =>  20.10  |  20.1259  ->  20.126  =>  20.15
20.1759  ->  20.175  =>  20.15  |  20.1759  ->  20.176  =>  20.20

As the above shows, these edge cases vary a great deal in the final result.

Argentinian currency rounding follows a similar model which just concerns itself with the third decimal digit. Although the rounded result may have two or three decimal places, the same principle applies; if the value to be rounded has four or more decimal digits, should the algorithm just truncate anything after the third digit or should it apply some other kind of intermediate rounding to get a three decimal place result first?

Thanks!

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-03-27 09:23

If less than 26, they are rounded down to 0; else if less than 76, rounded down to 5; else the whole value is rounded up.

By this I would assume the "Truncation" method would be appropriate, since 0.0259XXXXX is less than 0.026

查看更多
登录 后发表回答