How to translate number with customed currency symbol to number

  • Thread starter Thread starter zlf
  • Start date Start date
Z

zlf

Hi,
Run this code will cause format exception. I think the problem is
induced by using System.Globalization.NumberStyles.Currency since I used
customed currency symbol("My Dollar:").
Please tell me how to modify this block of code.Thanks

Console.WriteLine ( NumberValue.ToString ( formatString , n ) );

NumberFormatInfo numberFormatInfo = new
System.Globalization.NumberFormatInfo();
numberFormatInfo.CurrencySymbol = "My Dollar:";
string temp = "My Dollar:234.43";

double ret = double.Parse ( temp ,
System.Globalization.NumberStyles.Currency );

Console.WriteLine ( ret );
 
Hi,
Your problem is that your create the correct NumberFormatInfo but you do not
pass it to the double.Parse so the parsing function uses the system's
default currency format...
Modify the double.Parse call to the following:
double ret = double.Parse (temp, System.Globalization.NumberStyles.Currency,
numberFormatInfo);

Best regards,

Eran Kampf
http://www.ekampf.com/
http://www.ekampf.com/blog/
 
Back
Top