JavaScript toFixed, 实现四舍五入保留两位小数
const num = 18.186; let result; result = num.toFixed(2) console.log(result) // 18.19
注意,返回值为String类型
- 上一篇 »python 格式化输出保留一位小数
- 下一篇 »Java-数据字符串进行四舍五入
const num = 18.186; let result; result = num.toFixed(2) console.log(result) // 18.19
注意,返回值为String类型
1.结果保留小数点后一位,并且四舍五入sprintf('%.1f',$weight)