一、toFixed()方法
toFixed()方法是JavaScript内置的函数,可以用来将数字转为字符串,且保留指定位数的小数。
let num = 3.1415926;
let str = num.toFixed(2);
console.log(str); // "3.14"
在Vue中,可以通过将数据绑定至一个计算属性来使用toFixed()方法。
{{ num }}
{{ floatNum }}
原创文章,作者:小蓝,如若转载,请注明出处:https://www.506064.com/n/231551.html