how to get the leftmost digit of an int

Solutions on MaxInterview for how to get the leftmost digit of an int by the best coders in the world

showing results for - "how to get the leftmost digit of an int"
Enrico
28 Sep 2020
1# get the first digit
2def firstDigit(n) :
3    while n >= 10:
4        n = n / 10
5	return int(n)
6  
7# get the last digit
8def lastDigit(n) :
9    return n % 10
10
similar questions
queries leading to this page
how to get the leftmost digit of an int