How to get the last digit of a number in Ruby

2 Answers

0 votes
n = 38329

last_digit = n % 10

print last_digit



#
# run:
# 
# 9
#

 



answered Oct 17, 2021 by avibootz
0 votes
n = 38529

last_digit = n.digits[0]

print last_digit



#
# run:
# 
# 9
#

 



answered Oct 17, 2021 by avibootz
...