applyNumberFormat formats a value as a human-readable number (e.g., "1k", "1.2M").
(val reflect.Value, baseValue string)
| 586 | |
| 587 | // applyNumberFormat formats a value as a human-readable number (e.g., "1k", "1.2M"). |
| 588 | func applyNumberFormat(val reflect.Value, baseValue string) string { |
| 589 | if val.CanInterface() { |
| 590 | switch v := val.Interface().(type) { |
| 591 | case int: |
| 592 | return FormatNumber(v) |
| 593 | case int64: |
| 594 | // #nosec G115 - Converting int64 to int for display formatting |
| 595 | return FormatNumber(int(v)) |
| 596 | case int32: |
| 597 | return FormatNumber(int(v)) |
| 598 | case uint: |
| 599 | // #nosec G115 - Converting uint to int for display formatting |
| 600 | return FormatNumber(int(v)) |
| 601 | case uint64: |
| 602 | // #nosec G115 - Converting uint64 to int for display formatting |
| 603 | return FormatNumber(int(v)) |
| 604 | case uint32: |
| 605 | return FormatNumber(int(v)) |
| 606 | } |
| 607 | } |
| 608 | // Fallback: use integer kind directly, keeping signed and unsigned separate |
| 609 | // to avoid calling Int() on an unsigned kind (which panics). |
| 610 | switch { |
| 611 | case val.Kind() >= reflect.Int && val.Kind() <= reflect.Int64: |
| 612 | return FormatNumber(int(val.Int())) |
| 613 | case val.Kind() >= reflect.Uint && val.Kind() <= reflect.Uint64: |
| 614 | // #nosec G115 - Converting uint to int for display formatting |
| 615 | return FormatNumber(int(val.Uint())) |
| 616 | } |
| 617 | return baseValue |
| 618 | } |
| 619 | |
| 620 | // applyCostFormat formats a value as currency with $ prefix. |
| 621 | func applyCostFormat(val reflect.Value, baseValue string) string { |
no test coverage detected