How to translate number with currency format to pure number

Z

zlf

1¡¢Here is a number. double nu = 123
2¡¢Format it with [NumberFormatInfo]
3¡¢The result is "$123"

I want to ask how to deformat "$123" to 123
Thx
(Currency symbol is not restricted to '$')
 
G

Guest

hi zlf,

I have done something like this. Hope this helps!

// Gets a NumberFormatInfo associated with the en-US culture.
NumberFormatInfo nfi = new CultureInfo( "en-US", false ).NumberFormat;

double myInt = 123;
nfi.CurrencySymbol = "$";

//This will show the number formatted with $
Console.WriteLine(myInt.ToString( "C", nfi ));

//This will convert back the curreny amout without the $ symbol
Console.WriteLine(myInt.ToString( "N", nfi ));

Note: I have used Winform to test this code.

happy programming

pradeep_TP
 
D

Dale Preston

Decimal.Parse("$123.00",System.Globalization.NumberStyles.Currency)

Dale Preston
MCAD,MCDBA, MCSE
 
D

Dale Preston

Decimal.Parse("$123.00",System.Globalization.NumberStyles.Currency)

Dale Preston
MCAD,MCDBA, MCSE
 
Z

zlf

Thank you^_^
pradeep_TP said:
hi zlf,

I have done something like this. Hope this helps!

// Gets a NumberFormatInfo associated with the en-US culture.
NumberFormatInfo nfi = new CultureInfo( "en-US", false ).NumberFormat;

double myInt = 123;
nfi.CurrencySymbol = "$";

//This will show the number formatted with $
Console.WriteLine(myInt.ToString( "C", nfi ));

//This will convert back the curreny amout without the $ symbol
Console.WriteLine(myInt.ToString( "N", nfi ));

Note: I have used Winform to test this code.

happy programming

pradeep_TP

zlf said:
1?¡éHere is a number. double nu = 123
2?¡éFormat it with [NumberFormatInfo]
3?¡éThe result is "$123"

I want to ask how to deformat "$123" to 123
Thx
(Currency symbol is not restricted to '$')
 
Z

zlf

Thank you for your help.
But I executed the code just now and system will throw
System.FormatException in run-time. May you give me the code that can run
correctly. Thx
Dale Preston said:
Decimal.Parse("$123.00",System.Globalization.NumberStyles.Currency)

Dale Preston
MCAD,MCDBA, MCSE

zlf said:
1¡¢Here is a number. double nu = 123
2¡¢Format it with [NumberFormatInfo]
3¡¢The result is "$123"

I want to ask how to deformat "$123" to 123
Thx
(Currency symbol is not restricted to '$')
 
D

Dale Preston

Console.WriteLine(Decimal.Parse("$123.00",System.Globalization.NumberStyles.
Currency));

If you need a string, you just make it:

Console.WriteLine(Decimal.Parse("$123.00",System.Globalization.NumberStyles.
Currency).ToString());

Dale Preston

zlf said:
Thank you for your help.
But I executed the code just now and system will throw
System.FormatException in run-time. May you give me the code that can run
correctly. Thx
"Dale Preston" <[email protected]> дÈëÏûÏ¢ÐÂÎÅ:[email protected]...
Decimal.Parse("$123.00",System.Globalization.NumberStyles.Currency)

Dale Preston
MCAD,MCDBA, MCSE

zlf said:
1¡¢Here is a number. double nu = 123
2¡¢Format it with [NumberFormatInfo]
3¡¢The result is "$123"

I want to ask how to deformat "$123" to 123
Thx
(Currency symbol is not restricted to '$')
 
Z

zlf

Hi,Dale Preston
I know why system will throw exception when executing the code. The
reason is my location is out of US,but setting the currency to dollar. After
changing my location and currency format to US, the problem disappered.
Thank you very much:)
zlf
Dale Preston said:
Console.WriteLine(Decimal.Parse("$123.00",System.Globalization.NumberStyles.
Currency));

If you need a string, you just make it:

Console.WriteLine(Decimal.Parse("$123.00",System.Globalization.NumberStyles.
Currency).ToString());

Dale Preston

zlf said:
Thank you for your help.
But I executed the code just now and system will throw
System.FormatException in run-time. May you give me the code that can run
correctly. Thx
"Dale Preston" <[email protected]> дÈëÏûÏ¢ÐÂÎÅ:[email protected]...
Decimal.Parse("$123.00",System.Globalization.NumberStyles.Currency)

Dale Preston
MCAD,MCDBA, MCSE

1¡¢Here is a number. double nu = 123
2¡¢Format it with [NumberFormatInfo]
3¡¢The result is "$123"

I want to ask how to deformat "$123" to 123
Thx
(Currency symbol is not restricted to '$')
 

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