Chinese numbers converter for JavaScript

Anton Ivanov
Aug 29, 2017 · 1 min read

I was creating a consultant bot for a property agency, when it turned out that LUIS.ai (the AI that understands natural language) doesn’t recognize numbers like 345 萬 (it means 3,450,000 in Chinese and is often used in property prices).

This is why I’ve made a small JavaScript class that converts Chinese numbers (like 兩百四十五) into a JavaScript Number (like 245) that can be used in calculations or database queries.

For fun, I also decided to throw in support for some Cantonese slang, such as 廿yaa for 20, 卅saa for 30 and 卌sei aa for 40.

Some examples:

The code of chinese-numbers.js is in public domain on my GitHub.

)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade