[−][src]Module locale_settings::currency
Fetch locale-specific currency formatting settings.
The formatting information here does include the currency symbol,
international symbol, and precision all of which overlap with the
symbol
, alphabetic_code
, and subdivision exponent
from the
codes::currency
module. However, there is significantly more
information here and this should be used wherever necessary to
format currency values correctly.
However, values from the currency code can be used, for example the name and subdivision name(s), when labeling currency values.
Example
The following should display "19 US Dollars and 99 cents".
use std::str::FromStr; use locale_types::{Locale, LocaleString}; use locale_codes::currency; use locale_settings::locale::{Category, set_locale}; use locale_settings::currency::get_currency_format; let amount: f64 = 19.9950; let en_us = LocaleString::from_str("en_US.UTF-8").unwrap(); if set_locale(&Locale::String(en_us), &Category::Currency) { let format = get_currency_format(); let currency = currency::lookup_by_alpha(&format.international_format.unwrap().currency_symbol.trim()).unwrap(); let local = format.local_format.unwrap(); let subdiv = currency.subdivisions.get(0).unwrap(); let subdiv_name = &subdiv.name.clone().unwrap(); println!( "{0} {2} and {1:.4$} {3}", amount.trunc(), amount.fract(), currency.name, subdiv_name, local.decimal_precision ); }
Structs
CurrencyCellFormat | The actual formatting specification for the currency-specific part of a value. |
CurrencyFormat | The complete currency formatting rules. |
SignFormat | This denotes the complete handling of sign placement for a currency value. |
Enums
SignLocation | This enumeration defines the handling of sign placement and choice for either positive or negative numeric values. The examples for each use a value of minus 999.99. |
Functions
get_currency_format | Fetch the current local-specific currency formatting rules. |
get_currency_format_for_locale | Fetch the currency formatting rules for a specified |