1.1.1 • Published 2 years ago

@pansy/number-format v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

✨ 特性

  • 📦 开箱即用
  • 💝 无任何第三方依赖
  • 💻 使用 TypeScript 编写

🏗 安装

# npm install
$ npm install @pansy/number-format --save

# yarn install
$ yarn add @pansy/number-format

🔨 使用

import numberFormat from '@pansy/number-format';

// 直接使用
numberFormat().format(123456) 
// >> 123,456

// 不使用千分符
numberFormat({ thousandSeparator: false }).format(123456) 
// >> 123456

// 添加前缀
numberFormat({ prefix: '$' }).format(123456) 
// >> $123,456

// 添加后缀
numberFormat({ suffix: '/100' }).format(98) 
// >> 98/100

// 格式化
numberFormat({ template: '## [##] ##' }).format(123456) 
// >> 12 [34] 56

🎉 参数

参数名类型默认值描述
prefixstring--设置数值的前缀
suffixstring--设置数值的后缀
thousandSeparatorboolean | stringtrue设置千分位分隔符, true 默认为 ,
decimalSeparatorstring.设置小数点
precisionnumbertrue数值精度
templatestring--格式化的模板, 使用#占位