What is the best way to split some given larger number into hundreds, tens and units in C#?
For example: If I enter number 43928 how can I get 40000 + 3000 + 900 + 20 + 8 on the output?
Something like this:
long x = 43928;
long i = 10;
while (x > i / 10)
{
Console.WriteLine(x % i - x % (i / 10));
i *= 10;
}
it will give you output
8
20
900
3000
40000
You have to use the %
operator. Example:
43928 / 10000 = 4; 43928 % 10000 = 3928; 3928 /1000 = 3; 3928 %1000 = 928, etc...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With