瑞士和阿根廷货币四舍五入四舍五入 [英] Swiss and Argentinian currency fourth decimal digit rounding

查看:159
本文介绍了瑞士和阿根廷货币四舍五入四舍五入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用瑞士法郎的算法对货币金额进行四舍五入时,将考虑第二个和第三个十进制数字.如果小于26,则将其四舍五入为0;否则,将其四舍五入为0.否则,如果小于76,则四舍五入为5;否则,取整.否则,将整个值四舍五入.

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

当四舍五入的数字具有更高的十进制精度时,会发生什么?是仅将第三个数字后的所有十进制数字都忽略不计(值将被截断),还是首先以其他方式将值四舍五入为三个十进制数字?例如,考虑截断与"Math.round()"方法(向下取整小于0.5,否则向上取整):

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?

谢谢!

推荐答案

如果小于26,则将其四舍五入为0;否则,将其四舍五入为0.否则,如果小于76,则四舍五入为5;否则,取整.否则整个值将四舍五入.

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.

通过这种方式,我认为截断"方法是合适的,因为0.0259XXXXX小于0.026

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

这篇关于瑞士和阿根廷货币四舍五入四舍五入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆