-
Notifications
You must be signed in to change notification settings - Fork 62
Align Right? #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This sounds like a good option, have to think about a proper solution. The library just implements the Arduino print/write methods and these don't support padding or right alight. I should probably just add a custom method void printAlignRight(int number) {
if (number < 10) {
display.setCursor(0, 3);
}
else if ( number < 100) {
display.setCursor(0, 2);
}
else if (number < 1000) {
display.setCursor(0, 1);
} else {
display.setCursor(0, 0);
}
display.print(number);
} Hope this helps. |
Let me "improve" the example that @bremme has showed:
Hope it helps :) |
Hey sorry to take so long to join in. Thanks for addressing this. I came up with a similar solution to Bilick88's. Basically adding in space padding if the digits are shorter than a certain length. I'm not really very good at C optimization, so I'm not sure what is faster. But in my case I casted the int to a string and added spaces in a (While len < 4) loop. |
Hi there, has anyone got a solution for this issue? I've tested the above solutions and it changes nothing to my sketch. |
Thanks for this great library, @bremme ! I needed a right align number print function as well. However, the example functions above do not handle negative values. I made a few minor tweaks: void printNum(int number) {
bool negative = false;
display.clear();
if (number < 0) {
number = -number;
if (number >= 1000) {
display.print("----");
return;
}
negative = true;
}
if (number > 9999) {
display.print("----");
}
else {
if (number < 10) {
display.setCursor(0, 3);
}
else if ( number < 100) {
display.setCursor(0, 2);
}
else if (number < 1000) {
display.setCursor(0, 1);
} else {
display.setCursor(0, 0);
}
display.print(number);
}
if (negative) {
display.setCursor(0, 0);
display.print("-");
}
} |
Any way to make the digits align right instead of left when they are shorter than 4 digits?
The text was updated successfully, but these errors were encountered: