瑞士和阿根廷货币小数点后第四位四舍五入

发布于 2024-10-19 14:12:57 字数 913 浏览 1 评论 0原文

使用瑞士法郎算法对货币金额进行四舍五入时,会考虑第二个和第三个小数位。如果小于 26,则向下舍入为 0;否则,如果小于 76,则向下舍入为 5;否则整个值将向上舍入。

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

当要舍入的金额具有更高的小数精度时会发生什么?第三位之后的所有十进制数字是否都被简单地忽略(值被截断),或者该值是否首先以某种其他方式四舍五入到三位小数数字?例如,考虑截断与“Math.round()”方法(向下舍入小于 0.5,否则向上舍入):

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

如上所示,这些边缘情况在最终结果中变化很大。

阿根廷货币舍入遵循类似的模型,仅涉及小数点后第三位。尽管四舍五入的结果可能有两位或三位小数,但同样的原则适用;如果要舍入的值有四位或更多小数位,算法是否应该截断第三位数字之后的任何内容,还是应该应用某种其他类型的中间舍入以首先获得三位小数结果?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落在眉间の轻吻 2024-10-26 14:12:57

如果小于26,则向下舍入为0;否则,如果小于 76,则向下舍入为 5;否则整个值将向上舍入。

由此我认为“截断”方法是合适的,因为 0.0259XXXXX 小于 0.026

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文