Skip to main content

rule_of_72

Function rule_of_72 

Source
pub fn rule_of_72(rate: f64) -> FinanceResult<f64>
Expand description

Approximate years to double using the Rule of 72: 72 / (100 * rate).

rate is a decimal rate (e.g. 0.08 for 8%).

§Errors

FinanceError::ZeroValue if rate == 0, FinanceError::InvalidRate if rate < 0, or FinanceError::NonFinite if non-finite.

§Examples

use finance_solution::{rule_of_72, FinanceError};

assert_eq!((rule_of_72(0.08).unwrap() * 100.0).round() / 100.0, 9.0); // 72/8

match rule_of_72(0.0) {
    Err(FinanceError::ZeroValue { field }) => assert_eq!(field, "rate"),
    other => panic!("expected ZeroValue, got {other:?}"),
}