decimal.Parse and NumberStyles

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
 
G

Guest

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
 
K

Karl Seguin [MVP]

have you tried simply doing:

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

This should use the NumberStyle.Number.

It should work everywhere..

Karl
 
A

Andrew Wrigley

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]...
 

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