js金额转换单位万元,亿
export function million(value) {
if (!value) return 0;
if (typeof value == 'string') {
value = Number(value);
}
let unit = '';
const k = 10000;
const sizes = ['', '万元', '亿'];
let i;
if (value < k) {
return value + '元';
} else {
i = Math.floor(Math.log(value) / Math.log(k)); // 单位下标
value = value / Math.pow(k, i);
value = (parseInt(value * 100) / 100).toFixed(2);
unit = sizes[i];
}
return value + unit || 0;
}