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

number-to-chinese-words

v1.0.20

Published

Convert a number to chinese words. Inspired from number-to-words

Downloads

573

Readme

NPM

number-to-chinese-words

Convert a number to chinese words. 由數字轉為中文數目

此項目的測試以萬進制為基準,即10⁸為億,10¹²為兆 https://zh.wikipedia.org/wiki/%E5%84%84

Install

npm install number-to-chinese-words

API

The API is inspired from http://github.com/marlun78/number-to-words This package allow user to use same api from number-to-words for Chinese support.

toOrdinal(number)

將整數加上前置的「第」字。 如果輸入的數字包含小數點,小數點後的數目將會被移除。

var converter = require('number-to-chinese-words');
converter.toOrdinal(21); // => “第21”

toWords(number)

將數目轉換成文字。

// 整數:
var converter = require('number-to-chinese-words');
converter.toWords(13); // => “十三”

// Decimal numbers:
converter.toWords(2.9); // => “二點九”

// Negative numbers:
converter.toWords(-3); // => "負三"

// Large numbers:
converter.toWords(9007199254740992); // => “九千零七兆一千九百九十二億五千四百七十四萬零九百九十二”

toWordsOrdinal(number)

將整數轉換成文字,再加上前置的「第」字。 如果輸入的數字包含小數點,小數點後的數目將會被移除。

import converter from "number-to-chinese-words";
converter.toWordsOrdinal(21); // => “第二十一”

大寫

var converter = require("number-to-chinese-words")
converter.default.labels = Object.assign({},converter.default.labels, {
  digits : ['零','壹', '貳', '參', '肆', '伍', '陸', '柒', '捌', '玖'],
  units: ['','拾', '佰', '仟', '萬', '拾', '佰', '仟', '億', '拾', '佰', '仟', '兆', '拾', '佰', '仟', '京', '拾', '佰', '仟', '垓']
})

converter.toWords(199254740992); // => 壹仟玖佰玖拾貳億伍仟肆佰柒拾肆萬零玖佰玖拾貳

Direct load javascript from html

  <script src="//unpkg.com/number-to-chinese-words@^1.0/number-to-chinese-words.min.js"></script>
  <script>
    var converter = window.index.NumberToChineseWords;
    console.log(converter.toWords(13)); // => 十三
    console.log(converter.toWords(2.9)); // => 二點九
    console.log(converter.toWords(-3)); // => 負三
    console.log(converter.toWords(9007199254740992)); // => 九千零七兆一千九百九十二億五千四百七十四萬零九百九十二

    converter.labels = Object.assign({},converter.labels, {
      digits : ['零','壹', '貳', '參', '肆', '伍', '陸', '柒', '捌', '玖'],
      units: ['','拾', '佰', '仟', '萬', '拾', '佰', '仟', '億', '拾', '佰', '仟', '兆', '拾', '佰', '仟', '京', '拾', '佰', '仟', '垓']
    });

    console.log(converter.toWords(199254740992));// => 壹仟玖佰玖拾貳億伍仟肆佰柒拾肆萬零玖佰玖拾貳
  </script>