toFixed MDN
The toFixed() method uses fixed-point notation to format a number.
Keep two decimal places to round
Export function NumFilter (value) {let realVal = parseFloat(value).tofixed (2) return realVal}Copy the code
Leave two decimal places unrounded
Export function numFilter (value) {let tempVal = parseFloat(value). ToFixed (3) let realVal = tempVal.substring(0, tempVal.length - 1) return realVal }Copy the code
3. Convert decimals to percentages (keep two decimals and round them off)
export function ChangeDecimalToPercentage(data) {
let data1 = (data*100).toFixed(2)+"%"
return data1
}
Copy the code
Note: this must be used when converting decimals to percentages. ToFixed () retains the required number of digits, otherwise it defaults to many more decimals.