util-helpers
Version:
52 lines (51 loc) • 2.11 kB
TypeScript
type Options = {
big5?: boolean;
unit?: boolean;
decimal?: string;
zero?: string;
negative?: string;
unitConfig?: {
w?: string;
y?: string;
};
};
/**
* 数字转中文数字
*
* 如果数字不在安全数字 -9007199254740991~9007199254740991 范围内,处理会有异常。
*
* @alias module:Processor.numberToChinese
* @since 1.2.0
* @see {@link https://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=F5DAC3377DA99C8D78AE66735B6359C7 出版物上数字用法}
* @param {number} num 数字
* @param {Object} [options] 配置项
* @param {boolean} [options.big5=false] 繁体,默认`false`
* @param {boolean} [options.unit=true] 计数单位,默认`true`
* @param {string} [options.decimal="点"] 中文小数点。默认`点`,当`big5=true`时,默认`點`
* @param {string} [options.zero="零"] 设置0,默认`零`。常用配置 〇
* @param {string} [options.negative="负"] 负数前面的字,默认`负`
* @param {Object} [options.unitConfig] 节点单位配置
* @param {string} [options.unitConfig.w="万"] 设置计数单位万,默认`万`。常用配置 萬
* @param {string} [options.unitConfig.y="亿"] 设置计数单位亿,默认`亿`。常用配置 億
* @returns {string} 中文数字
* @example
*
* numberToChinese(100); // 一百
* numberToChinese(100.3); // 一百点三
* numberToChinese(1234567890); // 一十二亿三千四百五十六万七千八百九十
* numberToChinese(1234567890.11); // 一十二亿三千四百五十六万七千八百九十点一一
*
* // 繁体
* numberToChinese(100, {big5: true}); // 壹佰
* numberToChinese(100.3, {big5: true}); // 壹佰點叁
* numberToChinese(1234567890.11, {big5: true}); // 壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾點壹壹
*
* // 不带计数单位
* numberToChinese(1990, {unit: false}); // 一九九零
*
* // 不带计数单位,修改0
* numberToChinese(1990, {unit: false, zero:'〇'}); // 一九九〇
*
*/
declare function numberToChinese(num: number, options?: Options): string;
export default numberToChinese;