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?
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?
if you need numbers use int.Parse(a)
You have to use the
%
operator. Example:43928 / 10000 = 4; 43928 % 10000 = 3928; 3928 /1000 = 3; 3928 %1000 = 928, etc...
Something like this:
it will give you output
Linq implementation:
The way with the parsing:
Outputs this: