0

In my form textedit i get value "₹ 7,245.00" now I want to convert this textedit value into decimal for total calculation. I used this code but getting error like this "Invalid Input String"

 decimal Price = Convert.ToDecimal(Price.Text);

How to solve this ?. I need 7,245.00 only.

Srihari
  • 2,387
  • 9
  • 51
  • 82
  • 2
    I would recommend using the approach from the post @Junaith commented above, but you could however go the easy hacky way and do a Price.Text.SubString(1) if you know that the symbol would always be at position 0; before converting to decimal. – scheien Jan 29 '14 at 14:06
  • That or regex away anything but numbers, the period, comma and minus sign. – w5l Jan 29 '14 at 14:11

2 Answers2

1

Your text contains a non-parsable character . Strip it before parsing, or parse with AllowCurrencySymbol: How to parse string to decimal with currency symbol?

Community
  • 1
  • 1
w5l
  • 5,341
  • 1
  • 25
  • 43
1

try this...

    string s1 = Price.Text.Trim().Substring(1);
    decimal Price = Convert.ToDecimal(s1);

as it is working fine for me...

    string s = "₹ 7,245.00";
    string s1 = s.Substring(1);
    decimal Price = Convert.ToDecimal(s1);
Amit Tiwari
  • 368
  • 1
  • 4