如何在 Javascript 中舍入一个数字? [英] How can I round down a number in Javascript?

查看:25
本文介绍了如何在 Javascript 中舍入一个数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 JavaScript 中四舍五入一个数字?

How can I round down a number in JavaScript?

math.round() 不起作用,因为它将其四舍五入到最接近的小数.

math.round() doesn't work because it rounds it to the nearest decimal.

除了在小数点处将其分开以保留第一位之外,我不确定是否有更好的方法.一定有……

I'm not sure if there is a better way of doing it other than breaking it apart at the decimal point at keeping the first bit. There must be...

推荐答案

使用 Math.floor() 是一种方法.

更多信息:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor

这篇关于如何在 Javascript 中舍入一个数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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