PHP: Determine last digit of a number
Question by Guest | 2014-02-10 at 20:09
In one of my PHP scripts, I have to extract the last digit/figure from an integer value.
For example, given the number 231, I would like to get the cypher "1".
Is there any PHP function for this?
Related Topics
PHP: Get first Digit of Number or String
Tutorial | 0 Comments
PHP: Determine Week Number
Tutorial | 0 Comments
Delphi/Lazarus: 3 Ways to round a Number to X Decimal Places
Tutorial | 7 Comments
What are IBAN and BIC?
Info | 0 Comments
PHP: Check Strings with Ctype-Functions for Character Classes
Article | 0 Comments
MySQL/PHP: How to retrieve the last INSERT ID
Info | 0 Comments
PHP: Current Date and Time
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
To determine the last digit of a number, you can just use the modulo operator % like this:
The modulo operator returns the remainder of a division. So, 231 divided by 10 are 230 + a remainder of 1. And 1 is your required last figure.
2014-02-10 at 23:21