How to convert culture specific double using TypeConverter?
- by Christian
Hi I have a problem with the TypeConverter class. It works fine with CultureInvariant values but cannot convert specific cultures like english 1000 seperators. Below is a small test program that I cannot get to work.
using System;
using System.Globalization;
using System.ComponentModel;
namespace TestConvertCulture {
class Program {
static void Main() {
try {
var culture = new CultureInfo( "en" );
TypeConverter typeConverter = TypeDescriptor.GetConverter( typeof ( double ) );
double value = (double)typeConverter.ConvertFromString( null, culture, "2,999.95" );
Console.WriteLine( "Value: " + value );
}
catch( Exception e ) {
Console.WriteLine( "Error: " + e.Message );
}
}
}
}