MYR 货币四舍五入
寻求帮助,用 js 语言将钱四舍五入到最接近的 0.05。
输入&预期输出:
1.10 => 1.10
1.11 => 1.10 (round down)
1.12 => 1.10 (round down)
1.13 => 1.15 (round up)
1.14 => 1.15 (round up)
1.15 => 1.15
1.16 => 1.15 (round down)
1.17 => 1.15 (round down)
1.18 => 1.20 (round up)
1.19 => 1.20 (round up)
Looking for help in rounding the money to the nearest 0.05 in js language.
Input & Expected Output:
1.10 => 1.10
1.11 => 1.10 (round down)
1.12 => 1.10 (round down)
1.13 => 1.15 (round up)
1.14 => 1.15 (round up)
1.15 => 1.15
1.16 => 1.15 (round down)
1.17 => 1.15 (round down)
1.18 => 1.20 (round up)
1.19 => 1.20 (round up)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以采用偏移量并采用多层值。
如果您需要在末尾加零,请使用
.toFixed(2)
。You could take an offset and take a multiple floored value.
If you need zeroes at the end take
.toFixed(2)
.