Best way to convert back a currency string into a number(int or long)?

J

Juan

Best way to convert back a currency string into a number(int or long)?

If I have, for example, $ 15.000,00 what is the best way to make it again an
int or long?

pls help!,
Juan.
 
N

Nicholas Paldino [.NET/C# MVP]

Juvan,

I wouldn't use an int or a long (unless you know there are no cents).

If the currency format is how the current culture on the machine handles
it, then you can just call the static Parse method on the Decimal (which I
prefer for money calculations) or Double structure, passing c or C for the
format, indicating to use the currency format for the current culture on the
machine.

If this is not the currency format for the machine, then you can create
an instance of NumberFormatInfo, and set the following properties, and pass
it to the Parse method:

CurrencySymbol = "$"
CurrencyGroupSizes = 3
CurrencyGroupSeparator = "."
CurrencyDecimalDigits = 2
CurrencyDecimalSeparator = ","

Hope this helps.
 

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