当前位置:科技动态 > vue中数字的四舍五入操作

vue中数字的四舍五入操作

  • 发布:2023-10-10 01:22

关于数字的处理(四舍五入、上舍入、下舍入……)

可以在vue项目中新建一个filter.js文件,将这些filter全部写入该文件中,然后在页面中引用

1。显示小时、分钟和秒
格式 00:00:00
export const timeFilter = val => {
function p(t) {
return t < 10 ? '0' + t: t;
}
var h = Math.floor(val/1000/60/60);
var m = Math.floor(val/1000/60%60);
var s = Math.floor(val/1000%60);
var str = p(h) + ':' + p(m) + ':' + p(s);
return str
}
使用:

{{timeFilter(fileInfo.needTime) || ''}}
2. 向下取整函数
Math.floor();
例如:Math.floor( 23.2222222 ); // 23

3。向上取整
Math.ceil();
例如:Math.ceil(23.333333); // 24

4。四舍五入
Math.round();
例如:Math.round(23.33333); // 23

? // 36.365

相关文章

最新资讯