Check if the last digit in a 4 digit number is a 1

273 Views Asked by At

Is there a way to check if the last digit of a 4-digit (or any digit) number is a 1?

I am trying to make something that checks if the first and last digit of a number are both 1. Suppose our number is 1581. To check if the first digit is 1 is trivial. I can go..

if number - 2000 < 0 AND number - 999 > 0, then the first digit is always one.

Is there a test similar to above to check if the last digit is 1?

EDIT: Just to add more context to the question, we want to find an automated way to check if the number starts and ends with a 1.

2

There are 2 best solutions below

0
On BEST ANSWER

If it has MOD then something like $$MOD(1481,10)=1$$.
If it has FLOOR or INT to give the integer part, then $$1481-10×FLOOR(1481/10)=1$$

0
On

The following translates easily into most programming languages:

$$1000 \le x < 2000 \land x \mathrel{\mbox{mod}} 10 = 1$$

[And if you can, do tell us why you want to do this?]