Table of Contents
I introduce the way to convert number to word
PHP
PECL has a nice class, NumberFormatter
.
1 2 3 |
$f = new NumberFormatter("en", NumberFormatter::SPELLOUT); echo $f->format(1432); # => "one thousand four hundred thirty-two" |
JVM
I released the library (JAR) to convert number to word in JVM, written in Kotlin.
Here is a sample code in Kotlin.
1 2 3 4 5 |
NumberUtility.convertNum2String(842) // => "eight hundred and forty two" NumberUtility.convertNum2String(842, NumberUtility.Companion.NumberType.Ordinal) // => "eight hundred and forty second" |
Ruby
There are many gems for it. Here, I show a sample code of numbers_and_words
gem.
1 2 |
I18n.with_locale(:en) { 42.to_words } # => "forty-two" |
Python
num2words
is a good tool for it. You can download with pip install num2words
.
1 2 3 |
from num2words import num2words num2words(42) # => forty-two |