Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return last 5 digits of a number

Tags:

java

string

int

How do you only display the last 5 digits of a number?

Example input:

123456789

Would return: 56789

like image 858
Mike Richards Avatar asked Jan 30 '12 16:01

Mike Richards


1 Answers

Let's assume that required number to convert is an integer. Then you can use a modular mathematic - you can the number convert to the module with base 100 000. That means that only last 5 digits will be kept. The conversion can be done by an operator for remainder of division, the operator is %.

The code is:

int x = 123456;
int lastDigits = x % 100000;
like image 67
Gaim Avatar answered Oct 15 '22 11:10

Gaim