例如。如果我给 150//输出应该是 15.0 如果1565//输出应该是156.5
谁能提供上述逻辑的最佳代码吗?
最佳答案
使用.parseFloat()
和.toFixed(1)
将精度设置为1。 toFixed() 中提供的值将设置精度直到该值
var a = 150;
console.log(parseFloat(a / 10).toFixed(1))
a = 1565;
console.log(parseFloat(parseFloat(a / 10).toFixed(1))) //to get the output type as number
关于javascript - JQuery - 将整数更改为带有一位小数点的 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54664559/