Reference
Kanji numerals
import { … } from "@johnmorrisdotca/hikidashi/numerals";
1.8 kB minified and gzipped, with everything it imports (measured with esbuild)
漢数字: numbers, in both directions between the two ways of writing them.
一億二千万 is a number a learner meets in a news headline and cannot read, and 120,000,000 is a number they can read and cannot write. Japanese counts in ten-thousands rather than thousands (万, 億, 兆, each one 10,000 times the last), which is why 120 million is "twelve thousand ten-thousands" and why reading one off a page is a different skill from reading the digits. That grouping is the whole of this module.
parseJapaneseNumberreads 一億二千万, 1億2000万, 2万5千 or 120000000 and gives 120000000, or null.writeJapaneseNumberwrites it back, and withformalthe way a contract or a banknote does: 壱万.readJapaneseNumbersays it aloud in hiragana, with the sound changes (さんびゃく, はっぴゃく).parseEnglishNumberreads "five hundred", "twenty-five" and the magnitudes in romaji ("5 man").
Whole numbers from 0 to 9,007,199,254,740,991 only: past that JavaScript stops counting exactly, and a number the runtime cannot hold is worse than one that is not offered.
Exports
| Name | Kind | What it is |
|---|---|---|
LARGEST_JAPANESE_NUMBER | constant | The largest number this module will answer for: 9,007,199,254,740,991, JavaScript's largest safe integer. |
parseEnglishNumber | function | The value of a number written in words, or null when it is not one. |
parseJapaneseNumber | function | The value of a number written in Japanese, or null when it is not one. |
readJapaneseNumber | function | The number said aloud, in hiragana, with the sound changes a learner has to know: 300 is さんびゃく, 600 ろっぴゃく, 800 はっぴゃく, 3,000 さんぜん, 8,000 はっせん, and 一兆 いっちょう. |
writeJapaneseNumber | function | The number as Japanese writes it, in kanji. |