rmb.ts 854 Bytes
import currency from 'currency.js';

type RMBOption = { price?: number; symbol?: boolean; precision?: boolean };

// 人民币格式化
const RMB = ({ price = 0, symbol = true, precision = true }: RMBOption) => {
  return currency(price, {
    symbol: symbol ? '¥' : '',
    precision: precision ? 2 : 0,
  }).format();
};

// 人民币格式化-不包含符号和小数
const rmb = (price?: number) => RMB({ price, symbol: false, precision: false });

// 人民币格式化-包含符号,不包含小数
const rmbS = (price?: number) => RMB({ price, precision: false });

// 人民币格式化-包含小数,不包含符号
const rmbP = (price?: number) => RMB({ price, symbol: false });

// 人民币格式化-包含符号和小数
const rmbSP = (price?: number) => RMB({ price });

export default {
  _: rmb,
  s: rmbS,
  p: rmbP,
  sp: rmbSP,
};