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 🙏

© 2024 – Pkg Stats / Ryan Hefner

nzh

v1.0.12

Published

数字转中文,大写,金额

Downloads

24,604

Readme

Nzh

Nzh 适用于需要转换阿拉伯数字中文数字的场景。
特点如下:

  • 以字符串的方式转换,没有超大数及浮点数等问题(请自行对原数据进行四舍五入等操作)
  • 支持科学记数法字符串的转换
  • 支持口语化
  • 支持自定义转换(不论是,还是都可以用)
  • 对超大数支持用争议较少的万万亿代替亿亿
  • 当然,你还可以把中文数字再转回阿拉伯数字

安装

$ npm install nzh --save
$ bower install nzh --save

引用

var Nzh = require("nzh");
var nzhcn = require("nzh/cn"); //直接使用简体中文
var nzhhk = require("nzh/hk"); //繁体中文

注: 浏览器直接引用请使用 dist/文件夹中的文件 (适配CMD,AMD);

示例

var nzhcn = Nzh.cn;                 // 使用简体中文,  另外有 Nzh.hk -- 繁体中文

nzhcn.encodeS(100111);              // 转中文小写 >> 十万零一百一十一
nzhcn.encodeB(100111);              // 转中文大写 >> 壹拾万零壹佰壹拾壹
nzhcn.encodeS("1.23456789e+21");    // 科学记数法字符串 >> 十二万三千四百五十六万万七千八百九十万亿
nzhcn.toMoney("100111.11");         // 转中文金额 >> 人民币壹拾万零壹佰壹拾壹元壹角壹分

API

Nzh.cn / Nzh.hk

为方便使用,默认实现了两个对像:

  • Nzh.cn 简体中文
  • Nzh.hk 正体中文(繁体中文)

都包含以下方法:

  • encodeS(num,options) 转中文小写
  • encodeB(num,options) 转中文大写
  • toMoney(num,options) 转中文金额
  • decodeS(zh_num) 中文小写转数字
  • decodeB(zh_num) 中文大写转数字
// options.tenMin

// encodeS默认true
nzhcn.encodeS("13.5");                 // 十三点五
nzhcn.encodeS("13.5", {tenMin:false}); // 一十三点五
// encodeB默人false
nzhcn.encodeB("13.5");                 // 壹拾叁點伍
nzhcn.encodeB("13.5", {tenMin:true});  // 拾叁點伍

// options.ww

//Nzh.cn和Nzh.hk未引入兆、京等单位,超千万亿位时,默认以争议较少的万万亿为单位
nzhcn.encodeS(1e16);                // 一万万亿
nzhcn.encodeS(1e16, {ww: false});   // 一亿亿

// options.complete

nzhcn.toMoney("1");                        //人民币壹元整
nzhcn.toMoney("1",{complete:true});        //人民币壹元零角零分
nzhcn.toMoney("0.1");                      //人民币壹角
nzhcn.toMoney("0.1",{unOmitYuan:true});    //人民币零元壹角
nzhcn.toMoney("0.1",{complete:true});      //人民币零元壹角零分

//outSymbol  默认 true
nzhcn.toMoney("1");                        //人民币壹元整
nzhcn.toMoney("1",{outSymbol:false});      //壹元整

options 说明

  • tenMin: 十的口语化开关, 默认值为 false
    • 注: Nzh.cnNzh.hk中的encodeS方法默认 true
  • ww: "万万"化开关, 默认值为 true
  • unOmitYuan: 个为零时不省略元, toMoney 函数专用配置, 默认 false
  • complete: 输出完整金额开关, toMoney 函数专用配置, 默认 false
  • forceZheng: 以输出结果加“整”(只要输出的结果没有到分位就加“整”), toMoney 函数专用配置, 默认 false
  • outSymbol: 输出金额前缀字符, toMoney 函数专用配置, 默认 true

new Nzh(langs) 自定义

var nzh = new Nzh({
    ch: "〇壹贰叁肆伍陆柒捌玖",      // 数字字符
    ch_u: "个十百千万亿兆京",       // 数位单位字符,万以下十进制,万以上万进制,个位不能省略
    ch_f: "负",                   // 负字符
    ch_d: "点",                   // 小数点字符
    m_u: "元角分厘",              // 金额单位
    m_t: "人民币",                // 金额前缀
    m_z: "正"                    // 金额无小数后缀
});
nzh.encode("10001000000000000"); // 壹京〇壹兆
nzh.decode("壹兆");              // 1000000000000
nzh.toMoney("1.234");           // 人民币壹元贰角叁分肆厘

nzh.encode(num,options)

数字转中文

nzh.decode(zh_num,options)

中文转数字

nzh.toMoney(num,options)

数字转金额

参考资料