Hi Am using Arduino IDE, ESP32 and TFT display .
I can declare: float myFloat=02.45.
But I would like to display the leading zero when i use: tft.drawFloat(myFloat, 2, 85 , 90, 7);
Is this possible?
Regards
Hi Am using Arduino IDE, ESP32 and TFT display .
I can declare: float myFloat=02.45.
But I would like to display the leading zero when i use: tft.drawFloat(myFloat, 2, 85 , 90, 7);
Is this possible?
Regards
Print a zero, then the number, using separate functions.
Test the value of the float and if it is less that 10.00 print a zero then print the float
You should be able to use leading 0's with floats using printf() on an ESP32.
Zeropad.
float j = 9.7;
void setup() {
Serial.begin(115200);
Serial.println();
for (int i = 0; i < 6; i++) {
j += 0.1;
if (j < 10)
Serial.print("0");
Serial.println(j);
delay(200);
}
}
void loop() {}
float x = 2.45;
printf("x = %06.2f\n", x);
will print
x = 002.45
If you need to output it to TFT display - use sprintf and than print the string
Hi all.
Thank you for your replies.
Because aFloat is never above 9.00,
I have chosen this solution as it preserves the font size 7.
float aFloat=1.55;
tft.drawFloat(0,0,60,90,7); //The padding
tft.drawFloat(aFloat, 3, 87 , 90, 7); //The number
The result is 01.55
I like printf(), but you cannot choose fonts.
Thank you
Regards
Solution with sprintf is applicable to any font
Hi.
I am curious.
Please could you implement my code using your method?
Regards
Would be odd to have a display library that did not use the current font for print functions.
OK then.
Take a look at the photo below.
That shows the TFT font size 7.
It is a lovely simulation of a 7-segment display.
How can you implement this ;
tft.drawFloat(0,0,60,90,7);
using printf()?
If you know it you should share it. That's what the forum is-for!
I will then run your code and see what happens.
float aFloat=1.55;
tft.setTextFont(7);
tft.setCursor(60, 90);
tft.printf("%06.3f", aFloat);
I think you are having a laugh!
You swapped two lines of code for three!
However technically you are correct.
And it works.
Well Done.
Regards
The setTextFont() only needs to be done once, then that font will be used until it is changed with another setTextFont(). If you want to cut down on the number of lines of code, then either a function or macro could be used so that all the necessary data could be included in a single function call, similar to the call to drawFloat().
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.