npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

financialconversion

v1.1.5

Published

财务金额转换,阿拉伯数字转中文,中文转阿拉伯数字,数字大写,数字转中文,自定义转换字符

Readme

financialconversion

financialconversion适用于需要阿拉伯数字与中文数字之间互相转换的场景。

financialconversion特点

  • 以字符串的方式转换,没有超大数及浮点数等问题(请自行对原数据进行四舍五入等操作)
  • 支持口语化,如“壹佰亿零壹拾壹万零壹佰贰拾点贰壹”
  • 支持自定义转换(自定义位数,如可以将万亿 自定义为 兆)
  • 当然,你还可以把中文数字再转回阿拉伯数字
  • 支持自定义字符,随意转换

安装

npm install financialconversion --save

引用

import num2str from 'financialconversion';

示例

// 返回 壹分
const money1 = num2str.numToStrMoney(0.01) 
// 返回 壹佰亿零壹拾壹万零壹佰贰拾圆贰角壹分
const money2 = num2str.numToStrMoney(10000110120.21) 
// 返回 10000110120.21
const money3 = num2str.strToNumMoney('壹佰亿零壹拾壹万零壹佰贰拾圆贰角壹分')
// 返回 负壹分
const money4 = num2str.numToStrMoney(-0.01) 
// 返回 壹万亿圆整
const money4 = num2str.numToStrMoney('1000000000000')
// 返回 1000000000000
const money5 = num2str.strToNumMoney('壹万亿圆整')

// 返回 零点零零肆
const num1= num2str.numToStr(0.004) 
// 返回 壹佰亿零壹拾壹万零壹佰贰拾点贰壹
const num2= num2str.numToStr(10000110120.21) 
// 返回 10000110120.21
const num3= num2str.strToNum('壹佰亿零壹拾壹万零壹佰贰拾点贰壹')

修改语言

num2str.setLanguage('cn')
// 返回 一百二十三圆整
const money1 = num2str.numToStrMoney(123)
num2str.setLanguage('hk')
// 返回 肆佰伍拾陸圓壹角貳分
const money2 = num2str.numToStrMoney(456.12)

不止于此

我们还可以根据自己的需求设置不同的字符串

例如
// 将默认数字“0”,“1”分别改成了“凌”,“一”
num2str.setNums({ 0: "凌", 1: "一" })
// 将默认金额单位“圆”改成了“元”
num2str.setMoneyUnits({1:'元'})
// 扩展单位“兆”
num2str.setUnit({'1000000000000':'兆'})

// 返回 一佰亿凌一拾一万凌一佰贰拾元贰角一分
const money1 = num2str.numToStrMoney(10000110120.21) 
// 返回 10000110120.21
const money2 = num2str.strToNumMoney('一佰亿凌一拾一万凌一佰贰拾元贰角一分')

// 将默认小数分割符“点”别改成了“典”
num2str.setDecUnit({'.':'典'})
// 将默认位数“拾”,“佰”,“仟”分别改成了“时”,“摆”,“签”
num2str.setUnit({10: "时", 100: "摆", 1000: "签"})
// 返回 一摆亿凌一时一万凌一摆贰时典贰一
const num = num2str.numToStr(10000110120.21) 

API

|API| 参数 |默认参数|介绍 |--|--|--|--| | setLanguage| language{ String}|"default"|可选:"cn","hk"| | setNums | nums{ Object }||设置数字 详情见下 (获取参数示例)| | setUnit | units{ Object }||设置位数 详情见下 (获取参数示例)| | setDecUnit| decUnit{ Object }||设置小数点或整 详情见下 (获取参数示例)| | setMoneyUnits| moneyUnits{ Object }||设置金额单位 详情见下 (获取参数示例)| | numToStr| num{ number or string }||数字转中文 | numToStrMoney| num{ number or string }||数字金额转中文金额 | strToNum| num{ string }||中文转数字 | strToNumMoney| num{ string }||中文金额转数字金额

获取参数示例

// 返回所有参数示例
num2str.getDefaultParams()
{
  nums: {
    '0': '零',
    '1': '壹',
    '2': '贰',
    '3': '叁',
    '4': '肆',
    '5': '伍',
    '6': '陆',
    '7': '柒',
    '8': '捌',
    '9': '玖'
  },
  units: {
    '10': '拾',
    '100': '佰',
    '1000': '仟',
    '10000': '万',
    '100000000': '亿'
  },
  decUnit: { 
    '.': '点', 
    '/': '整' , 
    '-': '负' 
  },
  moneyUnits: { 
    '1': '圆', 
    '0.1': '角', 
    '0.01': '分', 
    '0.001': '毫', 
    '0.0001': '厘' 
  }
}

版本日志

1.1.5
  • 优化 可以自定义扩展单位,不限于兆、京等,具体需要Math.pow(10000,n),小数部分同理
  • 新增 去掉争议单位改为万亿,但是任然可以自定义扩展Math.pow(10000,n)作为单位,如设置num2str.setUnit({'1000000000000':'兆'})后,任然可以使用兆
  • 修复 部分数字转换错误
1.1.4
  • 新增 负数转换
  • 修复 小数点后口语化问题
1.1.3
  • 新增 setLanguage('hk')转换繁体大写 @param{'default'|'cn'|'hk'}
  • 新增 简体小写中文模板,“一,二,三,四”等,可以使用setLanguage('cn')切换
  • 修复 numToStrMoney(0)转换错误的问题
1.1.2
  • 修复 (0,1)区间内转换错误的问题
1.1.1
  • 优化 设置自定义字符时可只设置单个字符
1.1.0
  • 新增 setNums实现自定义转换数字字符
  • 新增 setUnit实现自定义位数字符
  • 新增 setDecUnit实现自定义小数分割字符
  • 新增 setMoneyUnits实现自定义金额单位字符
  • 新增 getDefaultParams实现获取当前默认字符配置
  • 新增 numToStr实现数字转中文
  • 新增 numToStrMoney实现数字转中文金额
  • 新增 strToNum实现中文数字转阿拉伯数字
  • 新增 strToNumMoney实现中文数字金额转阿拉伯数字
  • 弃用 lowerToupper,upperTolower方法
1.0.1 已废弃
  • 修复 转换大小限制,支持传入中文
  • 优化 压缩代码体积,优化性能
1.0.0 已废弃
  • 新增 lowerToupper,upperTolower方法,实现大小写转换