diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-10-25 20:30:59 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-10-25 20:30:59 +0300 |
commit | dd9a2a1f57f9c563d7307ed2249887786a2ed516 (patch) | |
tree | a052268123ab19549b02767b652092b0b09bffd3 | |
parent | 67078056b2e23c762cfc7fe8dc249ba49c41fe6b (diff) |
Avoid printing too many decimal places in some situations
-rw-r--r-- | src/ObjectModel/ObjectModel.cpp | 14 | ||||
-rw-r--r-- | src/ObjectModel/ObjectModel.h | 2 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/ObjectModel/ObjectModel.cpp b/src/ObjectModel/ObjectModel.cpp index a8a42ff4..d085beec 100644 --- a/src/ObjectModel/ObjectModel.cpp +++ b/src/ObjectModel/ObjectModel.cpp @@ -193,6 +193,20 @@ void ExpressionValue::Release() noexcept } } +// Get the format string to use assuming this is a floating point number +const char *ExpressionValue::GetFloatFormatString() const noexcept +{ + float f = 1.0; + unsigned int digitsAfterPoint = param; + while (digitsAfterPoint > 1 && fVal > f) + { + f *= 10.0; + --digitsAfterPoint; + } + + return ::GetFloatFormatString(digitsAfterPoint); +} + #if SUPPORT_CAN_EXPANSION // Given that this is a CanExpansionBoardDetails value, extract the part requested according to the parameter and append it to the string diff --git a/src/ObjectModel/ObjectModel.h b/src/ObjectModel/ObjectModel.h index 3202aa54..9ae99e80 100644 --- a/src/ObjectModel/ObjectModel.h +++ b/src/ObjectModel/ObjectModel.h @@ -194,7 +194,7 @@ struct ExpressionValue #endif // Get the format string to use assuming this is a floating point number - const char *GetFloatFormatString() const noexcept { return ::GetFloatFormatString(param); } + const char *GetFloatFormatString() const noexcept; // Append a string representation of this value to a string void AppendAsString(const StringRef& str) const noexcept; |