Skip to content

Instantly share code, notes, and snippets.

@andjc
Created February 27, 2022 06:54
Show Gist options
  • Select an option

  • Save andjc/b1188d33fb7790ee2c0e9e49fd2562ee to your computer and use it in GitHub Desktop.

Select an option

Save andjc/b1188d33fb7790ee2c0e9e49fd2562ee to your computer and use it in GitHub Desktop.
Using PyICU to format and spellout numbers

Spellout numbers

from icu import RuleBasedNumberFormat, URBNFRuleSetTag, Locale
n = 111000
formatter = RuleBasedNumberFormat(URBNFRuleSetTag.SPELLOUT, Locale("hi"))
formatter.format(n)   # 'एक लाख ग्यारह हज़ार'
formatter2 = RuleBasedNumberFormat(URBNFRuleSetTag.SPELLOUT, Locale("en_IN"))
formatter2.format(n)  #  lakh eleven thousand'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment