use super::funejson::Value; use super::math_round_div::round_div; use super::money_amount::{money, money_from_value, money_to_value, Money}; /// Apply a rate given in basis points (10000 = 100%). /// /// Rates are integers, never floats, so VAT, discounts, interest and /// commission all stay in exact arithmetic right up to the single rounding /// step the caller asked for. pub fn apply_rate(amount: &Money, basis_points: i64, mode: &str) -> Money { money( round_div(amount.minor * basis_points, 10000, mode), &amount.currency, ) } /// The complement: what is left after the rate is taken off. pub fn apply_rate_complement(amount: &Money, basis_points: i64, mode: &str) -> Money { money( amount.minor - apply_rate(amount, basis_points, mode).minor, &amount.currency, ) } pub fn fune_vector(args: &[Value]) -> Value { money_to_value(&apply_rate( &money_from_value(&args[0]), args[1].as_i64(), args[2].as_str(), )) }