Parsing a decimal number
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 T开发者_如何学PythonheValue 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?
Take a look at the decimal.Parse
overload that accepts a NumberStyles
enum. Specifically, you'll need to include NumberStyles.AllowParentheses
.
精彩评论