admin管理员组文章数量:1415484
How to get the rounding number of 0.5, previously I found in this link:
Click here
But this is not what I want:
I want like this example:
- 10.24 = 10.25
- 17.90 = 17.90
- 3.89 = 3.90
- 7.63 = 7.65
jQuery will be fine with me.
How to get the rounding number of 0.5, previously I found in this link:
Click here
But this is not what I want:
I want like this example:
- 10.24 = 10.25
- 17.90 = 17.90
- 3.89 = 3.90
- 7.63 = 7.65
jQuery will be fine with me.
Share Improve this question edited May 23, 2017 at 12:14 CommunityBot 11 silver badge asked Jun 30, 2015 at 13:31 azim hamdanazim hamdan 11310 bronze badges 2- Multiply by 20, round, then divide by 20 – Axel Guilmin Commented Jun 30, 2015 at 13:46
- Multiple by 20, in fact, then divide by 20. – rghome Commented Jun 30, 2015 at 13:47
2 Answers
Reset to default 6Use Math.round(num * 20) / 20
, if you are looking to round a number to nearest 0.05
.
This will do what you need...
function roundoff(value) {
return (Math.round(value / 0.05) * 0.05).toFixed(2);
}
Using Math.round
will round the value to the nearest 0.05, and then using toFixed(2)
will ensure the result has 2 decimal places, even if they're both zeros.
Here's a working example...
http://jsfiddle/xoo7c898/
本文标签: JavascriptRounding 2 decimal places of boundary 05Stack Overflow
版权声明:本文标题:Javascript : Rounding 2 decimal places of boundary 0.5 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745232969a2648908.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论