Allow drawFloat with decimal places = 0

See #1639
This commit is contained in:
Bodmer
2022-02-16 20:16:30 +00:00
parent 86101770ac
commit 032e54dd10
4 changed files with 10 additions and 3 deletions

View File

@ -5105,6 +5105,7 @@ int16_t TFT_eSPI::drawFloat(float floatNumber, uint8_t dp, int32_t poX, int32_t
uint8_t ptr = 0; // Initialise pointer for array
int8_t digits = 1; // Count the digits to avoid array overflow
float rounding = 0.5; // Round up down delta
bool negative = false;
if (dp > 7) dp = 7; // Limit the size of decimal portion
@ -5116,10 +5117,16 @@ int16_t TFT_eSPI::drawFloat(float floatNumber, uint8_t dp, int32_t poX, int32_t
str[ptr] = 0; // Put a null in the array as a precaution
digits = 0; // Set digits to 0 to compensate so pointer value can be used later
floatNumber = -floatNumber; // Make positive
negative = true;
}
floatNumber += rounding; // Round up or down
if (dp == 0) {
if (negative) floatNumber = -floatNumber;
return drawNumber((long)floatNumber, poX, poY, font);
}
// For error put ... in string and return (all TFT_eSPI library fonts contain . character)
if (floatNumber >= 2147483647) {
strcpy(str, "...");