views:

67

answers:

1

Guys, I have a string that contains a decimal number. The problem is, sometimes it is negative and it is stored in accounting format (positive number surrounded by parenthesis). In other words, I got a string like this:

string s = "(35.00)";

What I'm doing currently is:

decimal TheValue = decimal.Parse(s);

This value of TheValue should be -35.00. It apparently doesn't know what the parenthesis mean, so its just storing 0 in Thevalue. Anyone know how to make the decimal.Parse() function look for parenthesis?

+15  A: 

Take a look at the decimal.Parse overload that accepts a NumberStyles enum. Specifically, you'll need to include NumberStyles.AllowParentheses.

Tim Robinson
+1 - didn't know about that one
Andras Zoltan