function dealNum(price){if (price === 0) {return '0元'}const BASE = 10000const decimal = 0const SIZES = ["", "万", "亿", "万亿"];let i = undefined;let str = "";if (price) {if ((price > 0 && price < BASE) || (price < 0 && price > -10000)) {str = `${Math.round(price)}元`} else if (price < 0) {let num = Math.abs(price)i = Math.floor(Math.log(num) / Math.log(BASE))str = `${((num / Math.pow(BASE, i))).toFixed(decimal)}${SIZES[i]}`str = `-${str}`} else {i = Math.floor(Math.log(price) / Math.log(BASE))str = `${((price / Math.pow(BASE, i))).toFixed(decimal)}${SIZES[i]}`}return str} else {return '--'}
}
运行结果: