From 2a6187349a7a49e81033b550311c71c3318ce339 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Wed, 7 Sep 2022 18:33:10 +0200 Subject: [PATCH] Fix for flexible showing float on the LCD. --- UI.hpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/UI.hpp b/UI.hpp index 727f847..26bafff 100644 --- a/UI.hpp +++ b/UI.hpp @@ -6706,33 +6706,28 @@ void display_int(int16_t var, uint8_t size, bool zeros, bool brackets, bool sign void display_float(float var, uint8_t size_number, uint8_t size_fraction, bool zeros, bool brackets, bool sign) { char s[LCD_cols + 1]; - char f[LCD_cols + 1]; if (size_fraction > 0) { if (zeros == true && sign == true) - sprintf(f, "%%+0%d.%df", size_number + size_fraction + 2, size_fraction); + sprintf(s, "%+0*.*f", size_number + size_fraction + 2, size_fraction, var); else if (zeros == true && sign == false) - sprintf(f, "%%+0%d.%df", size_number + size_fraction + 1, size_fraction); + sprintf(s, "%0*.*f", size_number + size_fraction + 1, size_fraction, var); else if (zeros == false && sign == true) - sprintf(f, "%%+%d.%df", size_number + size_fraction + 2, size_fraction); + sprintf(s, "%+*.*f", size_number + size_fraction + 2, size_fraction, var); else if (zeros == false && sign == false) - sprintf(f, "%%%d.%df", size_number + size_fraction + 1, size_fraction); - - sprintf(s, f, var); + sprintf(s, "%*.*f", size_number + size_fraction + 1, size_fraction, var); } else { if (zeros == true && sign == true) - sprintf(f, "%%+0%dd", size_number + 1); + sprintf(s, "%+0*d", size_number + 1, var); else if (zeros == true && sign == false) - sprintf(f, "%%%0dd", size_number); + sprintf(s, "%0*d", size_number, var); else if (zeros == false && sign == true) - sprintf(f, "%%+%dd", size_number + 1); + sprintf(s, "%+*d", size_number + 1, var); else if (zeros == false && sign == false) - sprintf(f, "%%%dd", size_number); - - sprintf(s, f, int(var)); + sprintf(s, "%*d", size_number, var); } if (brackets == true) @@ -6744,7 +6739,6 @@ void display_float(float var, uint8_t size_number, uint8_t size_fraction, bool z } Serial.println(var); - Serial.println(f); Serial.println(s); display.print(s);