diff --git a/tm1637.py b/tm1637.py index 0f601f3..747090c 100644 --- a/tm1637.py +++ b/tm1637.py @@ -160,11 +160,14 @@ def hex(self, val): string = '{:04x}'.format(val & 0xffff) self.write(self.encode_string(string)) - def number(self, num): - """Display a numeric value -999 through 9999, right aligned.""" + def number(self, num, zeros=False): + """Display a numeric value -999 through 9999, right aligned or with leading zeros""" # limit to range -999 to 9999 num = max(-999, min(num, 9999)) - string = '{0: >4d}'.format(num) + if zeros: + string = "{:04d}".format(num) + else: + string = '{0:>4d}'.format(num) self.write(self.encode_string(string)) def numbers(self, num1, num2, colon=True):