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 213 views
1 answer 227 views
1 answer 259 views
1 answer 262 views
2 answers 361 views
1 answer 194 views
...