New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

chinese-numbers-converter

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chinese-numbers-converter

Converts Chinese numerals in a string into Arabic numerals.

  • 2.0.4
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

chinese-numbers-converter.js

Small library that converts Chinese numbers into arabic Number, such as 兩百四十五 into 245.

Language support

Supports Traditional, Simplified, Financial numbers and some dialects. Only integers are supported, except the limited support for Arabic decimal + Chinese number, like "3.5萬". The largest supported character is 億/亿.

Usage examples

The ChineseNumber class contains these methods:

  • toInteger() - converts a Chinese or mixed number into Arabic and returns a JavaScript Number type.
  • toArabicString() - translates the entire string (possibly with multiple numbers in it) and returns the same string, but with Arabic numbers.
  • isNumberOrSpace() - checks whether the character is part of a number (true) or unrelated text (false).
new ChineseNumber('兩百四十五').toInteger(); // 245 - Normal number
new ChineseNumber('345 萬').toInteger(); // 3,450,000 - Mixed Arabic and Chinese
new ChineseNumber('3.5萬').toInteger(); // 35,000 - The only supported type of decimals
new ChineseNumber(' 二〇一二年').toInteger(); // 2012 - Phone, year etc: without the words "thousand, hundred, ten"
new ChineseNumber('卅六').toInteger(); // 36 - Cantonese slang
new ChineseNumber('***貳佰零伍元***').toInteger(); // 205 - finance numbers 
new ChineseNumber('1000 and one').toInteger(); // 1000 - ignore non-Chinese words

Possible unexpected results

new ChineseNumber(' 二百 or 兩百').toInteger(); // 400 - do not try to parse multiple numbers at once

Availability

  • Standalone JS class - chinese-numbers.js
  • NPM package - chinese-numbers-converter

License and contributing

Unlicense / Public domain. You can do everything.

Pull requests and bug reports are welcome.

Keywords

FAQs

Package last updated on 10 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc