Return last 5 digits of a number

前端 未结 3 568
栀梦
栀梦 2021-02-14 05:17

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

Example input:

123456789

Would return: 56789

3条回答
  •  再見小時候
    2021-02-14 05:43

    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;
    

提交回复
热议问题