parseEnglishNumber関数
リファレンスの説明と例は英語です。見出しと目次は日本語です。
The value of a number written in words, or null when it is not one.
Digits are allowed inside it - "5 man", "20 thousand" - since that is how somebody actually types a magnitude they know the name of. Anything the table does not hold makes the whole thing null rather than a partial reading: "five cats" is not five, and answering as though it were would be a confident wrong answer to a question nobody asked.
インポート
import { parseEnglishNumber } from "@johnmorrisdotca/hikidashi/numerals";
ほかのエクスポート元: @johnmorrisdotca/hikidashi
定義
function parseEnglishNumber(text: string): number | null
引数
| 名前 | 型 | 説明 |
|---|---|---|
text | string | A number in English words ("five hundred", "twenty-five", "1.2 million"), or with a Japanese magnitude in romaji ("5 man", "3 oku"); digits may stand for any part. |
戻り値
number | null
The value; null when any word is not a number word ("five cats"), when there is nothing to read, or when the value is past 9,007,199,254,740,991 either way.
例
import { parseEnglishNumber } from "@johnmorrisdotca/hikidashi/numerals";
console.log(parseEnglishNumber("five hundred"), parseEnglishNumber("twenty-five thousand"), parseEnglishNumber("5 man"));
console.log(parseEnglishNumber("1.2 million"), parseEnglishNumber("five cats"));500 25000 50000
1200000 null出力(このページを作ったときに実行した結果)
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。