NumberF.I18n (NumberF v0.1.7)
View SourceFunctions for number internationalization and localization.
Summary
Functions
Formats a number as currency according to locale-specific settings.
Formats a number according to locale-specific settings.
Returns currency names for different languages.
Returns locale-specific number formatting settings.
Parses a localized number string into a floating-point value.
Spells out a number in the specified language.
Functions
Formats a number as currency according to locale-specific settings.
Parameters
number
: The number to formatlocale
: The locale code (e.g., "en-US", "fr-FR")options
: Additional formatting options:precision
: Number of decimal places (default: 2):currency_code
: ISO currency code to override the locale default:symbol
: Whether to include the currency symbol (default: true)
Examples
iex> NumberF.I18n.format_currency(1234.56, "en-US")
"$1,234.56"
iex> NumberF.I18n.format_currency(1234.56, "fr-FR")
"1 234,56 €"
iex> NumberF.I18n.format_currency(1234.56, "en-US", currency_code: "EUR")
"€1,234.56"
Formats a number according to locale-specific settings.
Parameters
number
: The number to formatlocale
: The locale code (e.g., "en-US", "fr-FR")options
: Additional formatting options:precision
: Number of decimal places (default: 2)
Examples
iex> NumberF.I18n.format_number(1234567.89, "en-US")
"1,234,567.89"
iex> NumberF.I18n.format_number(1234567.89, "fr-FR")
"1 234 567,89"
iex> NumberF.I18n.format_number(1234567.89, "de-DE", precision: 3)
"1.234.567,890"
Returns currency names for different languages.
Parameters
currency_code
: ISO currency codelanguage
: Language code
Examples
iex> NumberF.I18n.get_currency_names("USD", "en")
%{main: "dollars", sub: "cents"}
iex> NumberF.I18n.get_currency_names("EUR", "fr")
%{main: "euros", sub: "centimes"}
Returns locale-specific number formatting settings.
Parameters
locale
: The locale code (e.g., "en-US", "fr-FR")
Examples
iex> NumberF.I18n.get_locale_settings("en-US")
%{
thousands_separator: ",",
decimal_separator: ".",
currency_symbol: "$",
currency_symbol_first: true
}
iex> NumberF.I18n.get_locale_settings("fr-FR")
%{
thousands_separator: " ",
decimal_separator: ",",
currency_symbol: "€",
currency_symbol_first: false
}
Parses a localized number string into a floating-point value.
Parameters
number_string
: The string to parselocale
: The locale code (e.g., "en-US", "fr-FR")
Examples
iex> NumberF.I18n.parse_number("1,234.56", "en-US")
1234.56
iex> NumberF.I18n.parse_number("1 234,56", "fr-FR")
1234.56
Spells out a number in the specified language.
Parameters
number
: The number to spell outlanguage
: The language code (e.g., "en", "fr")options
: Additional options:capitalize
: Whether to capitalize the first letter (default: true):currency
: Whether to add currency names (default: false):currency_code
: ISO currency code (default: nil)
Examples
iex> NumberF.I18n.spell_number(42, "en")
"Forty-two"
iex> NumberF.I18n.spell_number(42, "fr")
"Quarante-deux"
iex> NumberF.I18n.spell_number(42.75, "en", currency: true, currency_code: "USD")
"Forty-two dollars and seventy-five cents"