fenzhi-utils
Version:
分值前端项目的js函数库
26 lines (24 loc) • 837 B
JavaScript
import { CustomIsNumeric } from './CustomIsNumeric.js';
import { CustomNumberToFixed } from './CustomNumberToFixed.js';
/**
* 转换成万的单位
* @param {number} num 转换成万的数字
* @param {number} digits 保留的小数位数
* @returns {string} 返回转换成万的组合
*/
/**
CustomTendToTurn(); // ''
CustomTendToTurn(113456789); // '11345.68'
CustomTendToTurn(-110000000); // '-11000.00'
CustomTendToTurn(11000); // '1.10'
CustomTendToTurn(-11000); // '-1.10'
CustomTendToTurn(11); // '0.00'
*/
export function CustomTendToWan(num, digits = 2) {
if (!CustomIsNumeric(num)) return '';
num = parseFloat(num);
let character = num >= 0 ? '' : '-'; // 符号
let shortNum = Math.abs(num);
shortNum = CustomNumberToFixed(shortNum / 10000, digits);
return character + shortNum;
}