//! Zahlen, wie die App sie zeigt: deutsch, Strich fuer unbekannt (Darstellung.swift `Format`). /// Ohne Gruppierung und Locale - fuer Texte, die aus Zahlen werden (Platz, Blinds). pub fn roh(x: f64) -> String { if x == x.round() && x.abs() < 1e15 { format!("{}", x as i64) } else { format!("{x}") } } /// Deutsch gerundet: Tausenderpunkt, Komma, hoechstens `stellen` Nachkommastellen (ohne Nullen hinten). pub fn zahl(x: Option, stellen: usize) -> String { let Some(x) = x.filter(|x| x.is_finite()) else { return "–".into() }; let fest = format!("{:.*}", stellen, x.abs()); let (ganz, bruch) = match fest.split_once('.') { Some((g, b)) => (g.to_string(), b.trim_end_matches('0').to_string()), None => (fest.clone(), String::new()), }; let mut gruppiert = String::new(); for (i, c) in ganz.chars().enumerate() { if i > 0 && (ganz.len() - i) % 3 == 0 { gruppiert.push('.'); } gruppiert.push(c); } let null = gruppiert == "0" && bruch.is_empty(); let minus = if x < 0.0 && !null { "-" } else { "" }; if bruch.is_empty() { format!("{minus}{gruppiert}") } else { format!("{minus}{gruppiert},{bruch}") } } /// Stellen nach Groesse: ab 100 keine, ab 10 eine, sonst zwei. pub fn auto(x: Option) -> String { let Some(v) = x else { return "–".into() }; let a = v.abs(); zahl(x, if a >= 100.0 { 0 } else if a >= 10.0 { 1 } else { 2 }) } pub fn prozent(x: Option) -> String { match x { Some(v) => format!("{} %", zahl(Some(v * 100.0), 0)), None => "–".into(), } } pub fn vorzeichen(x: Option, stellen: usize) -> String { let Some(v) = x else { return "–".into() }; let t = zahl(Some(v.abs()), stellen); if v > 0.0 { format!("+{t}") } else if v < 0.0 { format!("−{t}") } else { t } }