[英]simple way to make 3.2242143 to 3.2 using jquery
i have many data like this : 我有很多这样的数据:
3.23214215
but i want to use the 3.2
part , 但我想使用
3.2
部分,
what can i do using jquery , 我怎么用jquery,
thanks 谢谢
yourNumber.toFixed(1);
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Number/toFixed
You can use plain Javascript: 你可以使用普通的Javascript:
var n = 3.23214215
var fixed = n.toFixed(1)
你不需要jquery,普通的旧javascript做的诀窍:
var chopped = Math.floor(full_length * 10.0) / 10.0;
You can do it in plain old Javascript: 你可以用普通的旧Javascript来做到这一点:
var f = 3.23214215;
f *= 10;
var i = parseInt(f);
f = i / 10;
You could also look into the Math object. 您还可以查看Math对象。 There might be a rounding function in it.
可能有一个舍入函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.