mirror of
https://github.com/openai/codex.git
synced 2026-10-27 18:48:37 +00:00
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
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user