1、toFiexd(x) 限制保留小数点后几位小数 eg:保留两位小数:number.toFiecs(2) 值得注意的是 使用该方法转换后得到的数据是string类型 且转换时采取的是四舍五入
2、Math.floor(num) 向下取整【即去除小数点后面的数 往该数值最小的整数取值】 eg:Math.floor(13.89)=13 Math.floor(-13.89)=-14 如需保留小数 两位:eg:Math.floor(15.7784514000 * 100) / 100=15.77 三位:eg:Math.floor(15.7784514000 * 1000) / 1000=15.778
3、Math.ceil(num) 向上取整【即去除小数点后面的数 往该数值进1】 eg:Math.ceil(13.89)=14 Math.ceil(-13.89)=-13 如需保留小数 两位:eg:Math.ceil(15.7784514000 * 100) / 100=15.78 三位:eg:Math.seil(15.7784514000 * 1000) / 1000=15.779
4、Math.round(number) 返回四舍五入后的整数 eg:Math.round(13.89)=14 Math.round(-13.89)=-14 Math.round(13.49)=13 Math.round(-13.49)=-13 如需保留小数 两位 : eg:Math.round(15.7784514000 * 100) / 100=15.78 三位:eg:Math.round(15.7784514000 * 1000) / 1000=15.778【四舍五入】
5、match() 配置指定的值 返回值 可使用正则表达式匹配 str.match(/^\d+(?:\.\d{0,2})?/)) eg:Number(15.7784514000.toString().match(/^\d+(?:\.\d{0,2})?/)) 该方法使用的是字符串匹配 所以要进行数据的转换