2

We use following code to convert a decimal to a string,

td_1.InnerText = String.Format("{0:C}", price)

so the result could be any of following cases:

4.83 -> $4.83
0 -> $0.00
-30.24 -> ($30.24)

my question is if there any way I can reverse the string back to a signed decimal? For example:

$4.83 ->4.83
($30.24) -> -30.24

I tried decimal.tryparse, doesn't seem work. Here is my code

decimal number;
if (Decimal.TryParse(price, out number) && number <0)
               ...
GLP
  • 3,441
  • 20
  • 59
  • 91
  • 2
    Can yuo show us the code for what you tried so we can help you see where the problem is? Also, what happened when you used `TryParse`; what sort of exception did it throw? – George Stocker Mar 06 '14 at 20:05

1 Answers1

4

Have you tried adding NumberStyles, like:

decimal.Parse(currencyValue, NumberStyles.Currency);
tweellt
  • 2,171
  • 20
  • 28