[PR #14925] fix(format): preserve decimal precision for values >= 10 in HumanBytes #61620

Open
opened 2026-04-29 16:41:11 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14925
Author: @LincolnBurrows2017
Created: 3/18/2026
Status: 🔄 Open

Base: mainHead: fix/humanbytes-decimal-truncation


📝 Commits (2)

  • 83b1d93 fix: properly propagate error from reserveWorstCaseGraph in allocModel
  • 52703a2 fix(format): preserve decimal precision for values >= 10 in HumanBytes

📊 Changes

3 files changed (+8 additions, -1 deletions)

View changed files

📝 format/bytes.go (+2 -0)
📝 format/bytes_test.go (+5 -0)
📝 runner/ollamarunner/runner.go (+1 -1)

📄 Description

Description

Previously, HumanBytes would truncate decimals when value >= 10, causing 10.5 KB to display as "10 KB" instead of "10.5 KB".

This fix checks for fractional values before truncating to integer.

Bug Details

In the original code:

switch {
case value >= 10:
    return fmt.Sprintf("%d %s", int(value), unit)  // Bug: truncates 10.5 to 10
...
}

For example:

  • 10500 bytes = 10.5 KB was incorrectly displayed as "10 KB"
  • 10500000 bytes = 10.5 MB was incorrectly displayed as "10 MB"

Fix

The fix reorders the checks to handle fractional values >= 10 first:

switch {
case value >= 10 && value != math.Trunc(value):
    return fmt.Sprintf("%.1f %s", value, unit)  // 10.5 -> "10.5 KB"
case value >= 10:
    return fmt.Sprintf("%d %s", int(value), unit)  // 10.0 -> "10 KB"
...
}

Test Cases Added

Added test cases for values >= 10 with decimals:

  • 10500 bytes -> "10.5 KB"
  • 10500000 bytes -> "10.5 MB"
  • 10500000000 bytes -> "10.5 GB"

Fixes: decimal truncation bug in HumanBytes function


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/14925 **Author:** [@LincolnBurrows2017](https://github.com/LincolnBurrows2017) **Created:** 3/18/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/humanbytes-decimal-truncation` --- ### 📝 Commits (2) - [`83b1d93`](https://github.com/ollama/ollama/commit/83b1d935a9b4509d062a07b4fb15f57ab42e6746) fix: properly propagate error from reserveWorstCaseGraph in allocModel - [`52703a2`](https://github.com/ollama/ollama/commit/52703a25cbbc563298dfa1b577c615f49fd1fc6d) fix(format): preserve decimal precision for values >= 10 in HumanBytes ### 📊 Changes **3 files changed** (+8 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `format/bytes.go` (+2 -0) 📝 `format/bytes_test.go` (+5 -0) 📝 `runner/ollamarunner/runner.go` (+1 -1) </details> ### 📄 Description ## Description Previously, `HumanBytes` would truncate decimals when value >= 10, causing 10.5 KB to display as "10 KB" instead of "10.5 KB". This fix checks for fractional values before truncating to integer. ## Bug Details In the original code: ```go switch { case value >= 10: return fmt.Sprintf("%d %s", int(value), unit) // Bug: truncates 10.5 to 10 ... } ``` For example: - 10500 bytes = 10.5 KB was incorrectly displayed as "10 KB" - 10500000 bytes = 10.5 MB was incorrectly displayed as "10 MB" ## Fix The fix reorders the checks to handle fractional values >= 10 first: ```go switch { case value >= 10 && value != math.Trunc(value): return fmt.Sprintf("%.1f %s", value, unit) // 10.5 -> "10.5 KB" case value >= 10: return fmt.Sprintf("%d %s", int(value), unit) // 10.0 -> "10 KB" ... } ``` ## Test Cases Added Added test cases for values >= 10 with decimals: - 10500 bytes -> "10.5 KB" - 10500000 bytes -> "10.5 MB" - 10500000000 bytes -> "10.5 GB" Fixes: decimal truncation bug in HumanBytes function --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-29 16:41:11 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#61620