decimal.Parse and NumberStyles

  • Thread starter Thread starter Andrew Wrigley
  • Start date Start date
A

Andrew Wrigley

Hi, I have a string:

"100.00"

....that I want to parse into a decimal. So:

decimal d = decimal.Parse("100.00", System.Globalization.NumberStyles.Any)

On my dev machine (United Kingdom), this works fine, but on the US server it
says that the string is not in the correct format...

What am I doing wrong?

TIA

Andrew
 
Andrew,

if you have a variable in place of "100", check if it holds a proper
numerical value. if it is not a proper number, you might experience
'incorrect format' error.

Augustin
 
have you tried simply doing:

decimal d = decimal.Parse("100.00");

This should use the NumberStyle.Number.

It should work everywhere..

Karl
 
Augustin and Karl

Thanks your suggestions.

I think the problem was that I was doing:

string s = row.Cells[1].Text;

s.Substring(("£", string.Empty);

Instead of:

s = s.Substring(("£", string.Empty));

so the pound sign was not being removed. As £ is the currency sign for UK
locales, it worked fine, but in the US, the server wants dollars.

Thanks again, and sorry the bother.

The test site can be viewed at: www.wingspan.info/wmp

Andrew Wrigley

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:[email protected]...
 
Back
Top