0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Pythonで数値を言葉に変換!num2wordsの使い方

0
Last updated at Posted at 2026-08-04

初めに

プログラミングしている時,数値を言葉に簡単かつ大量に変換できなくて悩んだ事はあるでしょうか?その問題を解決してくれるのが Python num2words モジュール。

num2words とはなにか?

Pythonのnum2wordsモジュールは、数値を言葉に簡単に変換できるモジュールです。Pythonプログラム内の単語を表現された数値データを処理する作業が簡素化されます。

対応言語

現在使える言語と方言は56か国語(2026年八月現在)

一般的に使われる言語:

言語 コード
英語  en(標準)
日本語  ja
フランス語  fr

対応言語の詳細は:num2words

インストール

num2wordsをインストールする最も簡単な方法はpipを使用することです。

ターミナルからインストール

pip install num2words

ソースコードを使ってのインストール

python setup.py install
python setup.py test

# リンティングと複数のPython環境を含む完全なCIテストスイートを実行するには:
pip install tox
tox

(https://pypi.org/project/num2words より引用)

使用例

数値を言葉に

>>> from num2words import num2words
>>>num2words(114)
'one hundred and fourteen'
>>>num2words(611,lang='ja')
'六百十一'

序数

>>> from num2words import num2words
>>> num2words(202,to="ordinal")
'two hundred and second'

序数詞

>>> from num2words import num2words
>>> num2words(2026,to="ordinal_num")
'2026th'

通貨

>>> from num2words import num2words
>>> num2words(222,to="currency")
'two euro, twenty-two cents'

>>> from num2words import num2words
>>> num2words(2026,to="year")
'twenty twenty-six'

まとめ

機能 コマンド
数値から言葉  num2words(number)
数値から指定の言語 num2words(number,lang='language')
序数 num2words(number,to="ordinal")
序数詞 num2words(number,to="ordinal_num")
通貨 num2words(number,to="currency")
num2words(year,to="year")

参考元

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?