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

  • Thread starter Thread starter Juan
  • Start date Start date
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.
 
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.
 
Back
Top