For serial, that sure seems like the hardway of doing field widths and justification, especially since xxprintf() routines like sprintf() were designed to do it for you.
Why use a simple "%d" format, a buffer with spaces in it, and then have to calculate offsets and columns based on the output string, when sprintf() will do all that for you?
The default justification for "%d" is is right adjusted & padded with spaces which appears to be what was wanted.
i.e.
sprintf(buffer, "%8d", x); //8 characters, right adjusted, <space> padded
For the LCD, I'd be concerned that the example code breaks down when the numbers transition between the total number of digits.
i.e. when you print 100 and then print 15 the display will show 115 instead of 15.
The LCD line has to either be cleared prior to printing the number or the buffer needs to be a fixed width and filled with spaces.
sprintf() with a field width can do the space buffer fill and right adjust as shown above.
--- bill