From efab30992b28bb8fc5064dbac9c12090b8818e98 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Mon, 26 Oct 2026 20:18:09 +0000 Subject: [PATCH] Promote rounded token counts to the next compact unit (#57282) Compact token counts can round to `1000K`, `1000M`, or `1000B` near unit boundaries. Promote these values to the next suffix so, for example, `999,500` tokens displays as `1M` instead of `1000K`. GitOrigin-RevId: 803e7c8c8eebd61522fb717275b43904a5da056f --- codex-rs/tui/src/status/helpers.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/codex-rs/tui/src/status/helpers.rs b/codex-rs/tui/src/status/helpers.rs index 97ddfe6782..e9c318f6ff 100644 --- a/codex-rs/tui/src/status/helpers.rs +++ b/codex-rs/tui/src/status/helpers.rs @@ -113,11 +113,12 @@ pub(crate) fn format_tokens_compact(value: i64) -> String { } let value_f64 = value as f64; - let (scaled, suffix) = if value >= 1_000_000_000_000 { + // Promote values that would round to 1000 in the smaller unit. + let (scaled, suffix) = if value >= 999_500_000_000 { (value_f64 / 1_000_000_000_000.0, "T") - } else if value >= 1_000_000_000 { + } else if value >= 999_500_000 { (value_f64 / 1_000_000_000.0, "B") - } else if value >= 1_000_000 { + } else if value >= 999_500 { (value_f64 / 1_000_000.0, "M") } else { (value_f64 / 1_000.0, "K")