Parse string with thousands separator and decimal separator to decimal in CSharp

Description

The following code shows how to parse string with thousands separator and decimal separator to decimal.

Example


using System;/*w w w .j  av a 2  s  .com*/
using System.Globalization;
class MainClass
{
    public static void Main( )
    {
        
        
        string value = "987 654,321";
        NumberStyles style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands;
        CultureInfo provider = new CultureInfo("fr-FR");
        decimal number = Decimal.Parse(value, style, provider);  
        Console.WriteLine("'{0}' converted to {1}.", value, number);
    
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var