Return the last 5 digits of a number

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

Input Example:

123456789 

Would 56789 : 56789

+7
source share
3 answers

Suppose the required number to convert is an integer. Then you can use modular math - you can convert a number to a module with a base of 100,000. This means that only the last 5 digits will be saved. The conversion can be performed by the operator for the remainder of the division, the % operator.

The code:

 int x = 123456; int lastDigits = x % 100000; 
+26
source

I suggest using the module when working with integers:

 int someNumber = 123456789; int lastFive = someNumber % 100000; 

Something like that

+3
source

One approach is to do the following:

1) Convert a number to a string
2) Make sure the string contains more than 5 digits .
3) If so, enter the last five characters in the line .

There are links in the three steps above that show you how to implement them. Since this is homework, getting it to work remains as an exercise (the direction of my previous TP).

+3
source

All Articles