Minh Nguyen Minh Nguyen - 23 days ago 10
C# Question

Best way to extract the remainder of integer number

I know it is silly but I am wondering what is best way to get result like this:

223231 => 1
509048 => 8
348356 => 6
648353 => 3


Basically it will return the remainder from its nearest
'xxxx0'
value.

Any idea to use Math
(div, mode, bit operators...)
to accomplish this?

Answer

just get the remainder when you divide the number by 10.

rem = number%10;

12345 % 10 = 5.