在Javascript中汇款到最近的10美元 [英] Round money to nearest 10 dollars in Javascript
本文介绍了在Javascript中汇款到最近的10美元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将Javascript中的十进制数舍入到最接近的10?我的数学今天非常垃圾,可能是2小时的睡眠:/
How can I round a decimal number in Javascript to the nearest 10? My math is pretty rubbish today, it could be the 2 hour sleep :/
一些示例案例
$2823.66 = $2820
$142.11 = $140
$9.49 = $10
我知道我可能需要Math.round / floor的组合,但我似乎无法得到预期的结果。
I understand I probably need a combination of Math.round/floor but I can't seem to get expected result.
任何帮助/指针赞赏!
M
推荐答案
尝试
Math.round(val / 10) * 10;
这篇关于在Javascript中汇款到最近的10美元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文