rm-hull/luma.led_matrix

7-seg - How to align number to the right?

Closed this issue · 2 comments

Hey.
Sorry for my bad english.
I want to send 4-digits number to the 7-seg and i need to align it to the right side.
Now i am using code like this:
seg.text = (" ")+number
for skipping first 4 digits i am using 4 spaces.
Now my number raising to 5-digits. I need to erase one space manualy from the code.
Is there any way to automatize align to right?
Thanks for help.

Have a look at https://pyformat.info/#string_pad_align.

You should be able to do something like:

seg.text = '{:8d}'.format(number)

or if you want zero's:

seg.text = '{:08d}'.format(number)

Thank you very much. That works perfect!