LCD Numbers

hi, i m making button counter with arduino uno and LCD,
problem is

number start 0 at right side of display
when number increasing 9 to 10 it shift left to right side,
i want to start 0 digit at right last and it go 9 to 10 it shift left

or 000009 000010 at right last column

please help me
chetan
chetan98250@gmail.com

Pseudo code:

if number < 10 then print a space;
print the number.

numbers are 000000 to 25000

Go on. Think about it. You want a field width of 5 digits. But if the value is zero, you want 6 digits.

Most people would choose a field width of 5 digits and pad with “0”
Or choose a field width of 6 and pad with spaces.

// start with temp holding the max number of padding zeros e.g. 4 for 00009
for (long temp = 10000; value < temp; temp /= 10) {
     Serial.print("0");
}

Untested.

You would do the same for hexadecimal. But obviously use 0x10000 and divide by 0x10

David.

This is the kind of stuff that the xxprintf() routines were designed for.
If you can afford to give up about 1.5k of code space you can use the routines.

i.e.
Add this to your code:

char buf[8];

    snprintf(buf, sizeof(buf), "%05d", your-desired-number);
    lcd.setCursor(your-desired-column, your-desired-row);
    lcd.print(buf);

You can google printf() to see how to use the format string:
http://www.cplusplus.com/reference/cstdio/printf/
In this example:
"%05d" tells the routine that it is to create a 5 character output string that is an integer number and that it should be zero filled if it is less than 5 digits.
If you leave out the 0 then it will fill with spaces rather than zeros.

--- bill