Skip to content

fix #4150: display 0°C instead of -0°C for near-zero negative temperatures#4186

Merged
jamesarich merged 5 commits into
meshtastic:mainfrom
lohwasser:bugfix/4150-negative-zero-temp
Jan 13, 2026
Merged

fix #4150: display 0°C instead of -0°C for near-zero negative temperatures#4186
jamesarich merged 5 commits into
meshtastic:mainfrom
lohwasser:bugfix/4150-negative-zero-temp

Conversation

@lohwasser

Copy link
Copy Markdown
Contributor

Summary

Fixes the negative zero temperature display bug, where values between -0.4°C and -0.1°C would incorrectly show as -0°C.

Fixes #4150

Changes

Modified files:

  • core/model/src/main/kotlin/org/meshtastic/core/model/util/UnitConversions.kt - Updated toTempString() to use absolute value rounding with separate sign handling
  • core/model/src/test/kotlin/org/meshtastic/core/model/util/UnitConversionsTest.kt - Added unit tests for temperature conversion

Implementation details:

The toTempString() function now:

  1. Rounds the absolute temperature value
  2. Determines sign separately
  3. Ensures zero is always displayed without a negative sign

This approach handles the edge case where %.0f formatting produces -0 for values between -0.4 and -0.1.

Testing

Added unit tests including:

  • Data-driven test cases covering the reported bug scenario
  • Boundary tests around the -0.5°C rounding threshold
  • Fahrenheit conversion tests
  • Dew point calculation tests

Run tests:

./gradlew :core:model:testGoogleDebugUnitTest --tests "org.meshtastic.core.model.util.UnitConversionsTest"

Note: I don't have a node with a temperature sensor to verify on-device, but the fix is in a pure function with full unit test coverage.

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
@CLAassistant

CLAassistant commented Jan 11, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added the bugfix PR tag label Jan 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread core/model/src/main/kotlin/org/meshtastic/core/model/util/UnitConversions.kt Outdated
Comment thread core/model/src/main/kotlin/org/meshtastic/core/model/util/UnitConversions.kt Outdated
Comment thread core/model/src/main/kotlin/org/meshtastic/core/model/util/UnitConversions.kt Outdated
@DaneEvans

DaneEvans commented Jan 12, 2026

Copy link
Copy Markdown
Collaborator

Bot's comments look reasonable, please make the changes.

And I definitely appreciate the added tests !

lohwasser and others added 3 commits January 13, 2026 13:17
…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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@jamesarich jamesarich enabled auto-merge January 13, 2026 12:27
@codecov

codecov Bot commented Jan 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (b131003) to head (0ac45aa).
⚠️ Report is 3 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@jamesarich jamesarich added this pull request to the merge queue Jan 13, 2026
Merged via the queue into meshtastic:main with commit 80996f2 Jan 13, 2026
12 checks passed
@lohwasser lohwasser deleted the bugfix/4150-negative-zero-temp branch January 13, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix PR tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: -0 degrees doesn't make sense, show decimal places?

5 participants