{"id":13493175,"url":"https://github.com/cnwhy/nzh","last_synced_at":"2025-05-14T14:08:23.756Z","repository":{"id":20807322,"uuid":"24092794","full_name":"cnwhy/nzh","owner":"cnwhy","description":"数字转中文（大写，小写）数字，金额。","archived":false,"fork":false,"pushed_at":"2024-10-09T09:07:57.000Z","size":288,"stargazers_count":1497,"open_issues_count":6,"forks_count":134,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-26T00:03:34.874Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://blog.whyoop.com/nzh/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cnwhy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-16T09:08:04.000Z","updated_at":"2025-04-23T05:50:03.000Z","dependencies_parsed_at":"2024-09-30T14:23:18.325Z","dependency_job_id":"2e1b81aa-c3fe-4867-a89d-c8ec5d6a5e17","html_url":"https://github.com/cnwhy/nzh","commit_stats":{"total_commits":81,"total_committers":9,"mean_commits":9.0,"dds":0.2592592592592593,"last_synced_commit":"030cb342f39c48b29f37078308b5636e5a7f097d"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnwhy%2Fnzh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnwhy%2Fnzh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnwhy%2Fnzh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnwhy%2Fnzh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cnwhy","download_url":"https://codeload.github.com/cnwhy/nzh/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251352594,"owners_count":21575862,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T19:01:12.926Z","updated_at":"2025-05-14T14:08:23.735Z","avatar_url":"https://github.com/cnwhy.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Nzh\n\n`Nzh` 适用于需要转换**阿拉伯数字**与**中文数字**的场景。  \n特点如下:  \n - 以字符串的方式转换，没有超大数及浮点数等问题(请自行对原数据进行四舍五入等操作)\n - 支持科学记数法字符串的转换\n - 支持口语化\n - 支持自定义转换(不论是`兆`,`京`还是`厘`都可以用)\n - 对超大数支持用争议较少的`万万亿`代替`亿亿`\n - 当然,你还可以把中文数字再转回阿拉伯数字\n\n## 安装\n\n```sh\n$ npm install nzh --save\n$ bower install nzh --save\n```\n\n## 引用\n\n```javascript\nvar Nzh = require(\"nzh\");\nvar nzhcn = require(\"nzh/cn\"); //直接使用简体中文\nvar nzhhk = require(\"nzh/hk\"); //繁体中文\n```\n\u003e 注: 浏览器直接引用请使用 `dist/`文件夹中的文件 (适配CMD,AMD);\n\n## 示例\n\n```javascript\nvar nzhcn = Nzh.cn;                 // 使用简体中文,  另外有 Nzh.hk -- 繁体中文\n\nnzhcn.encodeS(100111);              // 转中文小写 \u003e\u003e 十万零一百一十一\nnzhcn.encodeB(100111);              // 转中文大写 \u003e\u003e 壹拾万零壹佰壹拾壹\nnzhcn.encodeS(\"1.23456789e+21\");    // 科学记数法字符串 \u003e\u003e 十二万三千四百五十六万万七千八百九十万亿\nnzhcn.toMoney(\"100111.11\");         // 转中文金额 \u003e\u003e 人民币壹拾万零壹佰壹拾壹元壹角壹分\n```\n\n## API\n\n### Nzh.cn / Nzh.hk\n\n为方便使用，默认实现了两个对像: \n\n - `Nzh.cn` 简体中文\n - `Nzh.hk` 正体中文(繁体中文)\n\n都包含以下方法:\n\n - `encodeS(num,options)` 转中文小写\n - `encodeB(num,options)` 转中文大写\n - `toMoney(num,options)` 转中文金额\n - `decodeS(zh_num)` 中文小写转数字\n - `decodeB(zh_num)` 中文大写转数字\n \n```javascript\n// options.tenMin\n\n// encodeS默认true\nnzhcn.encodeS(\"13.5\");                 // 十三点五\nnzhcn.encodeS(\"13.5\", {tenMin:false}); // 一十三点五\n// encodeB默人false\nnzhcn.encodeB(\"13.5\");                 // 壹拾叁點伍\nnzhcn.encodeB(\"13.5\", {tenMin:true});  // 拾叁點伍\n\n// options.ww\n\n//Nzh.cn和Nzh.hk未引入兆、京等单位，超千万亿位时，默认以争议较少的万万亿为单位\nnzhcn.encodeS(1e16);                // 一万万亿\nnzhcn.encodeS(1e16, {ww: false});   // 一亿亿\n\n\n// options.outputString\n\nconsole.log(nzhcn.decodeS('一万万万万亿', {outputString: false}));   // 1e+24\nconsole.log(nzhcn.decodeS('一万万万万亿', {outputString: true}));    // \"1000000000000000000000000\"\n\n// options.complete\n\nnzhcn.toMoney(\"1\");                        //人民币壹元整\nnzhcn.toMoney(\"1\",{complete:true});        //人民币壹元零角零分\nnzhcn.toMoney(\"0.1\");                      //人民币壹角\nnzhcn.toMoney(\"0.1\",{unOmitYuan:true});    //人民币零元壹角\nnzhcn.toMoney(\"0.1\",{complete:true});      //人民币零元壹角零分\n\n//outSymbol  默认 true\nnzhcn.toMoney(\"1\");                        //人民币壹元整\nnzhcn.toMoney(\"1\",{outSymbol:false});      //壹元整\n```\n### options 说明\n - `tenMin`: 十的口语化开关, 默认值为 `false`\n    - *注: `Nzh.cn`和`Nzh.hk`中的`encodeS`方法默认 `true`*\n - `ww`: \"万万\"化开关, 默认值为 `true`\n - `outputString` 中文数字转阿阿拉伯数字时, 输出为字符串类型, 解决输出对出超大数时可能输出科学计数法的问题，默认 `false`;\n - `unOmitYuan`: 个为零时不省略元, `toMoney` 函数专用配置, 默认 `false` \n - `complete`: 输出完整金额开关, `toMoney` 函数专用配置, 默认 `false` \n - `forceZheng`: 以输出结果加“整”（只要输出的结果没有到分位就加“整”）, `toMoney` 函数专用配置, 默认 `false` \n - `outSymbol`: 输出金额前缀字符, `toMoney` 函数专用配置, 默认 `true` \n\n### new Nzh(langs) 自定义\n\n```javascript\nvar nzh = new Nzh({\n    ch: \"〇壹贰叁肆伍陆柒捌玖\",      // 数字字符\n    ch_u: \"个十百千万亿兆京\",       // 数位单位字符，万以下十进制，万以上万进制，个位不能省略\n    ch_f: \"负\",                   // 负字符\n    ch_d: \"点\",                   // 小数点字符\n    m_u: \"元角分厘\",              // 金额单位\n    m_t: \"人民币\",                // 金额前缀\n    m_z: \"正\"                    // 金额无小数后缀\n});\nnzh.encode(\"10001000000000000\"); // 壹京〇壹兆\nnzh.decode(\"壹兆\");              // 1000000000000\nnzh.toMoney(\"1.234\");           // 人民币壹元贰角叁分肆厘\n```\n\n#### nzh.encode(num,options)\n数字转中文\n\n#### nzh.decode(zh_num,options)\n中文转数字\n\n#### nzh.toMoney(num,options)\n数字转金额\n\n## 参考资料\n- [繁读法](https://baike.baidu.com/item/%E7%B9%81%E8%AF%BB%E6%B3%95)\n- [中文数字](https://baike.baidu.com/item/%E4%B8%AD%E6%96%87%E6%95%B0%E5%AD%97)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcnwhy%2Fnzh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcnwhy%2Fnzh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcnwhy%2Fnzh/lists"}