use std::collections::HashMap;
use crate::decimal::Decimal;
pub(crate) fn print_spaces(n: usize) {
if n > 0 {
print!("{}", " ".repeat(n));
}
}
pub(crate) fn push_spaces(out: &mut String, n: usize) {
out.reserve(n);
for _ in 0..n {
out.push(' ');
}
}
pub(crate) fn format_amount(
commodity: &str,
value: &Decimal,
precisions: &HashMap<String, usize>,
) -> String {
let prec = precisions.get(commodity).copied().unwrap_or(2);
let formatted = value.format_decimal(prec);
let formatted = if let Some(without_minus) = formatted.strip_prefix('-') {
if without_minus.chars().all(|c| c == '0' || c == '.') {
without_minus.to_string()
} else {
formatted
}
} else {
formatted
};
format!("{}{}", commodity, formatted)
}