Parsing numbers based on Culture info : Number Parse « I18N Internationalization « C# / CSharp Tutorial






using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Threading;
using System.Globalization;

public class MainClass
{
    public static void Main()
    {
        CultureInfo current = CultureInfo.CurrentCulture;
        string numberString = "33,223.510";

        try
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de-DE");

            try
            {
                double number = double.Parse(numberString);
                Console.WriteLine("Parsed! {0}", number);
            }
            catch (Exception e)
            {
                Console.WriteLine("Caught exception: {0}", e.ToString());
            }
        }
        finally
        {
            Thread.CurrentThread.CurrentCulture = current;
        }
    }
}








21.9.Number Parse
21.9.1.Parsing numbers based on Culture info
21.9.2.Parsing numbers with culture invariant parsing