Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2021-10-25 20:30:59 +0300
committerDavid Crocker <dcrocker@eschertech.com>2021-10-25 20:30:59 +0300
commitdd9a2a1f57f9c563d7307ed2249887786a2ed516 (patch)
treea052268123ab19549b02767b652092b0b09bffd3
parent67078056b2e23c762cfc7fe8dc249ba49c41fe6b (diff)
Avoid printing too many decimal places in some situations
-rw-r--r--src/ObjectModel/ObjectModel.cpp14
-rw-r--r--src/ObjectModel/ObjectModel.h2
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;