How can i get the last digit of an integer (or NSInteger) outputted to integer?
example:
int time = CFAbsoluteGetCurrent();
int lastDigit;
To find the last digit of a number, we use modulo operator %. When modulo divided by 10 returns last digit of the input number.
To find first digit of a number we divide the given number by 10 until number is greater than 10. At the end we are left with the first digit.
Use modulo:
int lastDigit = time % 10;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With