Skip to content

Add leading zero option to number() method #1

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions tm1638.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,14 @@ def hex(self, val):
string = '{:08x}'.format(val & 0xffffffff)
self.segments(self.encode_string(string))

def number(self, num):
def number(self, num, leading_zero = False): # add leading zero to number
"""Display a numeric value -9999999 through 99999999, right aligned."""
# limit to range -9999999 to 99999999
num = max(-9999999, min(num, 99999999))
string = '{0: >8d}'.format(num)
if leading_zero: # if add leading zero
string = '%08d' % num # using format string to add leading zero
else:
string = '{0: >8d}'.format(num)
self.segments(self.encode_string(string))

#def float(self, num):
Expand Down