How to translate number with customed currency symbol to number

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 );
 
E

Eran Kampf

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/
 
Z

zlf

Hi,
I modify my code with your suggestion and it runs correctly.Thank you
very much.

zlf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top