From bfb8d3b53e2c20e3eab901cd2fe5cd5ca813a80a Mon Sep 17 00:00:00 2001
From: Guthenberg <david.tim@web.de>
Date: Thu, 1 Dec 2016 15:40:57 +0100
Subject: [PATCH] Show more decimals in Display, if possible

_123, -123, _-12, __-1  plus  1234, 12.3, -1.2
---
 Marlin/utility.cpp | 24 ++++++++++++++++++++++++
 Marlin/utility.h   |  4 ++--
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/Marlin/utility.cpp b/Marlin/utility.cpp
index 8f06817c0f..31be8275ce 100644
--- a/Marlin/utility.cpp
+++ b/Marlin/utility.cpp
@@ -129,6 +129,30 @@ void safe_delay(millis_t ms) {
     return conv;
   }
 
+  // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
+  char *ftostr4sign(const float& fx) { 
+    int x = fx * 10, xx = abs(x);
+    bool ispos = x >= 0,
+         isten = xx >= 100,
+         ishun = xx >= 1000;
+    if (!isten || (ispos && !ishun)) {
+      // 12.3, _1.2, -1.2
+      conv[0] = ispos ? (isten ? DIGIMOD(xx, 100) : ' ') : '-';
+      conv[1] = DIGIMOD(xx, 10);
+      conv[2] = '.';
+      conv[3] = DIGIMOD(xx, 1);
+    }
+    else {
+      // 1234, _123, -123, _-12
+      conv[0] = ispos ? (xx >= 10000 ? DIGIMOD(xx, 10000) : ' ') : (ishun ? '-' : ' ');
+      conv[1] = ishun ? DIGIMOD(xx, 1000) : '-';
+      conv[2] = DIGIMOD(xx, 100);
+      conv[3] = DIGIMOD(xx, 10);
+    }
+    conv[4] = '\0';
+    return conv;
+  }
+
   // Convert float to fixed-length string with +123.4 / -123.4 format
   char* ftostr41sign(const float& x) {
     int xx = x * 10;
diff --git a/Marlin/utility.h b/Marlin/utility.h
index 95c9857937..4bdf18f344 100644
--- a/Marlin/utility.h
+++ b/Marlin/utility.h
@@ -69,8 +69,8 @@ void safe_delay(millis_t ms);
   // Convert float to rj string with 123 or -12 format
   FORCE_INLINE char *ftostr3(const float& x) { return itostr3((int)x); }
 
-  // Convert float to rj string with _123, -123, _-12, or __-1 format
-  FORCE_INLINE char *ftostr4sign(const float& x) { return itostr4sign((int)x); }
+  // Convert float to rj string with 1234, _123, 12.3, _1.2, -123, _-12, or -1.2 format
+  char *ftostr4sign(const float& fx);
 
 #endif // ULTRA_LCD
 
-- 
GitLab