Skip to content

Add leading zero capabilities to number display function #1848

Discussion options

You must be logged in to vote

The inclusion of drawNumber and drawFloat is historical for board packages that did not include printf() or sprintf(). You can use these for example:

  tft.setCursor(x, y);
  tft.printf("%02d:%02d", 3, 4);

  char str[10];
  sprintf(str, "%02d:%02d", 3, 4);
  tft.drawString(str, x, y);

Since the printf function is so flexible it does not seem worth adding another function variant to the library.

For floating point numbers it is best to draw the value with right justification, then the decimal point stays in the same place (caveat is that the digits are monospaced), i.e. use the setTextDatum() function plus setTextPadding() to wipe leading characters as required.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@erdosip
Comment options

Answer selected by erdosip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1846 on May 25, 2022 23:28.