Making Convert.ToDecimal() adapt to the language settings

  • Thread starter Thread starter Gustaf
  • Start date Start date
G

Gustaf

I read some data from an XML file. Some datas need to be converted to
decimals. The program is to be used in any country, so sometimes the
decimal sign is "." and sometimes ",". How can I make
Convert.ToDecimal() adapt to the user's language settings? Assume
Windows XP and .NET Framework 1.1.

Gustaf
 
Gustaf,

Instead of using Convert, use the static Parse method on the Decimal
type, the overload which passed in the IFormatProvider.

Hope this helps.
 
Nicholas said:
Instead of using Convert, use the static Parse method on the Decimal
type, the overload which passed in the IFormatProvider.

Thanks, you give me hope this can be solved. But I'll need some further
help on how to specify the IFormatProvider. I tried
NumberStyles.AllowDecimalPoint and NumberFormatInfo.CurrentInfo, but I
still get the System.FormatException error when I feed Decimal.Parse()
with numbers with the "wrong" decimal character.

Gustaf
 

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

Back
Top