fix #4150: display 0°C instead of -0°C for near-zero negative temperatures#4186
Merged
jamesarich merged 5 commits intoJan 13, 2026
Merged
Conversation
Fixes the negative zero display bug where temperatures between -0.4°C and -0.1°C would incorrectly show as \"-0°C\". The fix uses absolute value rounding with separate sign handling to ensure values that round to zero always display without a negative sign. Also adds comprehensive unit tests for temperature formatting including: - Data-driven test cases for various temperature values - Boundary tests around -0.5°C rounding threshold - Fahrenheit conversion tests - Dew point calculation tests Fixes meshtastic#4150
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #4150 where temperatures between -0.4°C and -0.1°C would incorrectly display as -0°C instead of 0°C. The fix implements a more careful rounding approach by handling the absolute value and sign separately.
Changes:
- Updated
toTempString()function to round absolute temperature values and handle the sign separately to avoid negative zero display - Added comprehensive unit tests covering the bug scenario, boundary cases, and Fahrenheit conversions
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
core/model/src/main/kotlin/org/meshtastic/core/model/util/UnitConversions.kt |
Refactored toTempString() to use absolute value rounding with separate sign determination to prevent -0°C display |
core/model/src/test/kotlin/org/meshtastic/core/model/util/UnitConversionsTest.kt |
Added comprehensive unit tests for temperature formatting including edge cases, boundary conditions, and Fahrenheit conversions |
Collaborator
|
Bot's comments look reasonable, please make the changes. And I definitely appreciate the added tests ! |
…Conversions.kt Fixed variable name typo Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: lowi <75674438+lohwasser@users.noreply.github.com>
…Conversions.kt better comment Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: lowi <75674438+lohwasser@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4186 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 3 3
Lines 23 23
Branches 7 7
=====================================
Misses 23 23 ☔ View full report in Codecov by Sentry. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the negative zero temperature display bug, where values between
-0.4°Cand-0.1°Cwould incorrectly show as-0°C.Fixes #4150
Changes
Modified files:
core/model/src/main/kotlin/org/meshtastic/core/model/util/UnitConversions.kt- UpdatedtoTempString()to use absolute value rounding with separate sign handlingcore/model/src/test/kotlin/org/meshtastic/core/model/util/UnitConversionsTest.kt- Added unit tests for temperature conversionImplementation details:
The
toTempString()function now:This approach handles the edge case where
%.0fformatting produces-0for values between -0.4 and -0.1.Testing
Added unit tests including:
Run tests:
./gradlew :core:model:testGoogleDebugUnitTest --tests "org.meshtastic.core.model.util.UnitConversionsTest"