Skip to content

number封装(big.js)

  • 处理number运算进度丢失问题
  • 处理toFixed精度丢失问题
  • 处理 round 四舍五入

useNumber

返回一个实例化的Big对象

Parameters:

  • n: - 待处理的数字/字符串数字

Examples:

ts
const value = useNumber('1')

round

4舍5入(精度兼容)

Parameters:

  • n: - 保留位数
  • rm: - 0: 向下取整 1: 四舍五入 2: 向上取整

Examples:

ts
const value = useNumber('1').round(0, 1)

formatNumber

格式化数字, 默认千位分隔符为","

Examples:

ts
formatNumber(1000) //输出 "1,000"
formatNumber(1234567) //输出 "1,234,567"
formatNumber(1234.5678, { precision: 2, thousandSeparator: '-' }) // 输出: "1-234.5678"

formatMoney

格式化金钱

Examples:

ts
formatMoney(1000) // 输出: "1000"
formatMoney(1234567) // 输出:"123万4567"
formatMoney(10000000) // 输出: "1000万"
formatMoney(9007199254740992) // 输出: "90071992亿5474万992"

Released under the MIT License.