index.js
export function reserveDecimal(value) {
let val = Math.round(parseFloat(value) * 100) / 100
const xsd = val.toString().split('.')
if (xsd.length === 1) {
if (+value !== 0) {
val = val.toString() + '.00'
return val
} else {
return 0
}
}
if (xsd.length > 1) {
if (xsd[1].length < 2) {
val = value.toString() + '0'
}
return val
}
}
页面使用
import { reserveDecimal } from '@/utils/index'
let attendanceScore=reserveDecimal(item.attendanceScore)