How to convert number to words in java

前端 未结 27 3217
遇见更好的自我
遇见更好的自我 2020-11-21 23:53

We currently have a crude mechanism to convert numbers to words (e.g. using a few static arrays) and based on the size of the number translating that into an english text. B

27条回答
  •  没有蜡笔的小新
    2020-11-22 00:27

    You can use RuleBasedNumberFormat. for example result will give you Ninety

    ULocale locale = new ULocale(Locale.US);  //us english
    Double d = Double.parseDouble(90);
    NumberFormat formatter = new RuleBasedNumberFormat(locale, RuleBasedNumberFormat.SPELLOUT);
    String result = formatter.format(d);
    

    It supports a wide range of languages.

提交回复
热议问题