elixir-cldr / cldr

Elixir implementation of CLDR/ICU
Other
447 stars 33 forks source link

[Spellout] Do not support for float number #143

Closed quan-nh2 closed 3 years ago

quan-nh2 commented 3 years ago

Code:

MyAdmin. Cldr.Number.to_string 1234.4, format: :spellout

{:error,
 {Cldr.Rbnf.NoRuleForNumber,
  "rule group :spellout_numbering for locale \"en\" does not know how to process 1234.4"}}

Could you support convert from float numbers to words in the future? Thank you!

kipcole9 commented 3 years ago

Thanks for the issue. The Rules Based Number Formats (RBNF) are not always complete for floating point numbers for all locales and there isn't an easy way to introspect the rules either.

However for the "en" locale, the ruleset :spellout_cardinal does implement floating point support. So for example:

iex> Cldr.Number.to_string 1234.4, format: :spellout_cardinal, locale: "en"        
{:ok, "one thousand two hundred thirty-four point four"}

# Just notices that this format was not in the `Cldr.Number.to_string/3` api
# So I have added it and it will be published in the next version in April with
# CLDR 39 data.
iex> Cldr.Number.to_string 1234.4, format: :spellout_cardinal_verbose, locale: "en"
{:ok, "one thousand two hundred and thirty-four point four"}

Hopefully this fulfils your immediate need - please let me know if not!

quan-nh2 commented 3 years ago

So great! Thanks for your support!