Return last 5 digits of a number

前端 未结 3 766
被撕碎了的回忆
被撕碎了的回忆 2021-02-14 05:31

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

Example input:

123456789

Would return: 56789

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-14 05:39

    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;
    

提交回复
热议问题