Units: modify displayed precision adjustment logic #2717
+82
−23
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.
Previously, when the units of a value was scaled up, we did not increase the displayed precision. Thus, a value with precision 0 such as 12345 W would be scaled up to 12.345 kW and then trimmed to 12 kW due to the specified precision.
This commit adjusts the logic to allow increasing the precision so long as the total number of digits is less than 4. That is, 12345 W will now be displayed as 12.35 kW.
Previously, the decimal point character seemed to have been considered to take up a "digit" when calculating whether to trim the precision in some cases (e.g. for precision 2 values with 2 non-decimal digits, precision was trimmed to just 1).
This commit removes that consideration, which allows removal of some unnecessary special-casing for Volts unit values.
Contributes to issue #2705