How to get the first digit of a float number in Python

1 Answer

0 votes
def get_first_digit(f):
    return int(str(f)[:1])

f = 234.872
first_digit = get_first_digit(f)

print(first_digit)   # prints 2


'''
run:

2

'''

 



answered Aug 29, 2019 by avibootz
edited Sep 15 by avibootz
...