Double TryParse, NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands : double parse « Data Types « C# / C Sharp






Double TryParse, NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands

  
using System;

using System.Globalization;

class MainClass{
   public static void Main(){  
        string value;
        NumberStyles style;
        CultureInfo culture;
        double number;

        value = "1.2345,978";
        style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands;
        culture = CultureInfo.CreateSpecificCulture("es-ES");
        if (Double.TryParse(value, style, culture, out number))
           Console.WriteLine("Converted '{0}' to {1}.", value, number);
        else
           Console.WriteLine("Unable to convert '{0}'.", value);
        
        value = "1 2345,978";
        if (Double.TryParse(value, style, culture, out number))
           Console.WriteLine("Converted '{0}' to {1}.", value, number);
        else
           Console.WriteLine("Unable to convert '{0}'.", value);

   }
}

   
    
  








Related examples in the same category

1.Converts string to double floating-point number
2.Converts string in a culture-specific format to double
3.Parse a string in exponential notation with only the AllowExponent flag
4.Parse a string in exponential notation with the AllowExponent and Number flags.
5.Parse a currency value with leading/trailing white space and white space after the U.S. currency symbol.
6.Parse negative value with thousands separator and decimal.
7.Parse a floating-point value with a thousands separator.
8.Parse a floating-point value with a currency symbol and a thousands separator.
9.Parse value in exponential notation.
10.Parse a negative integer value.
11.Double TryParse, NumberStyles.AllowDecimalPoint
12.Format decimal with currency format
13.double value parse: NumberStyles.AllowParentheses | NumberStyles.AllowTrailingSign | NumberStyles.Float | NumberStyles.AllowThousands
14.Converts string in a specified style and culture-specific format to double
15.Use TryParse to Convert string to double