Split number into hundreds tens and units using C#

前端 未结 5 1056
星月不相逢
星月不相逢 2021-01-03 13:00

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 + 2

5条回答
  •  渐次进展
    2021-01-03 13:12

    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
    

提交回复
热议问题