金额千分位处理——适用于只读

在财务软件中,涉及金额的字段需要加千分位分隔符,accounting.js 就是这样一个工具。

1、npm安装包。npm install accounting --save
2、引入。import accounting from 'accounting';
3、通用配置。

import accounting from 'accounting';
accounting.settings = {
  currency: {
    symbol: '¥', // default currency symbol is '$'
    format: '%s%v', // controls output: %s = symbol, %v = value/number (can be object: see below)
    decimal: '.', // decimal point separator
    thousand: ',', // thousands separator
    precision: 2 // decimal places
  },
  number: {
    precision: 0, // default precision on numbers is 0
    thousand: ',',
    decimal: '.'
  }
};

4、使用。

accounting.formatMoney()  // 金额处理
accounting.formatNumber() // 数字加千分位

5、使用时单独配置。

accounting.formatNumber(12345.11, 3, " "); // 12 345.110
accounting.formatMoney(12345.11, "¥", 2, ",", "."); // ¥12,345.11
accounting.toFixed(102.58, 1); //四舍五入为 102.6
accounting.unformat("¥12,345.11"); //将金额格式恢复为数字 12345.11
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值