How to parse a string with commas to a number in C#

1 Answer

0 votes
using System;
using System.Globalization;

class Program
{
    static void Main() {
        string str = "1,984,032";
        
        int num;
        int.TryParse(str, NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out num);

        Console.Write(num);
    }
}



/*
run:

1984032

*/

 



answered Jun 21, 2022 by avibootz

Related questions

1 answer 120 views
1 answer 131 views
1 answer 166 views
1 answer 147 views
2 answers 233 views
1 answer 102 views
...