Java implementation of sum in words

Question:

Is there a library implementation of translating sum into words in Russian? If not, how to implement it in an optimal way?

Answer:

You can use the ready-made Icu4j library:

RuleBasedNumberFormat nf = new RuleBasedNumberFormat(Locale.forLanguageTag("ru"),
        RuleBasedNumberFormat.SPELLOUT);
System.out.println(nf.format(1234567));
// один миллион двести тридцать четыре тысячи пятьсот шестьдесят семь

RuleBasedNumberFormat nf = new RuleBasedNumberFormat(Locale.forLanguageTag("pl"),
        RuleBasedNumberFormat.SPELLOUT);
System.out.println(nf.format(1234567));
// jeden milion dwieście trzydzieści cztery tysiące pięćset sześćdziesiąt siedem

RuleBasedNumberFormat nf = new RuleBasedNumberFormat(Locale.forLanguageTag("en"),
        RuleBasedNumberFormat.SPELLOUT);
System.out.println(nf.format(1234567));
// one million two hundred thirty-four thousand five hundred sixty-seven

RuleBasedNumberFormat nf = new RuleBasedNumberFormat(Locale.forLanguageTag("de"),
        RuleBasedNumberFormat.SPELLOUT);
System.out.println(nf.format(1234567));
// eine Million zwei-hundert-vier-und-dreißig-tausend-fünf-hundert-sieben-und-sechzig
Scroll to Top