Add leading zero capabilities to number display function #1848
-
Hy! I would like an improvement to the function drawNumber() (and maybe for drawFloat() ) The length is a minimum number of digits/chars to display So for example, is I wanted to have my month of the year displayed in two digit format, i did this: DummyLCD.Print_Number_Int(now.month(), 84, 287, 3, '0', 10);
The 84/287 are the coordinates, the 3 is the lenght (which include the not shown sign, if I'm right) and the '0' is the leading char (but you can use space, or any other char), which is included before the actual number, to get the proper constant lenght, and let the text displayed staying at the same place. I know, that I can code this in my own code, but if the library can support it, that would be more elegant I think. The same can be applied to drawFloat too, where the decimals are good, but if I want to display 1.234566 or 11.234567 the number will be moving. Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The inclusion of drawNumber and drawFloat is historical for board packages that did not include printf() or sprintf(). You can use these for example:
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. |
Beta Was this translation helpful? Give feedback.
The inclusion of drawNumber and drawFloat is historical for board packages that did not include printf() or sprintf(). You can use these for example:
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.