Skip to main content

codewhale_command_contract/
money.rs

1//! Shared, data-only precise monetary display for diagnostic reports.
2//! Currency selection and accounting remain authoritative on the host.
3
4use crate::types::CommandCurrency;
5
6#[must_use]
7pub fn format_cost_amount_precise(amount: f64, currency: CommandCurrency) -> String {
8    let symbol = match currency {
9        CommandCurrency::Usd => "$",
10        CommandCurrency::Cny => "¥",
11    };
12    if amount == 0.0 {
13        format!("{symbol}0.0000")
14    } else if amount > 0.0 && amount < 0.0001 {
15        format!("<{symbol}0.0001")
16    } else {
17        format!("{symbol}{amount:.4}")
18    }
19}