use super::funejson::Value; use super::money_currency_digits_data::CURRENCY_DIGITS; /// Decimal places in a currency's minor unit, per ISO 4217. /// /// Dividing by 100 is wrong for yen, won, dinar and a few dozen others, so /// anything moving between minor and major units asks here. /// /// # Panics /// Panics if the code is not an active ISO 4217 currency with a minor unit. pub fn currency_digits(currency: &str) -> i64 { match CURRENCY_DIGITS.iter().find(|c| c.code == currency) { Some(row) => row.digits, None => panic!("no ISO 4217 minor unit for currency \"{}\"", currency), } } pub fn fune_vector(args: &[Value]) -> Value { Value::Int(currency_digits(args[0].as_str())) }