News

Statistics

Locations of visitors to this page

Personal

February 2008 Entries

Convert Currency string back to decimal


I just came upon this issue. I have a textbox that contains a value formatted to currency :

        Decimal val = 567.3;
        CultureInfo ci = new CultureInfo("en-GB");
        string currency = val.ToString("C", ci);

this produces string : 567.3 "
       
And in another place I needed the number from currency, so I had to convert the formatted currency back to decimal.
And here's the tip:

  string currency = 567.3 ";
  CultureInfo ci = new CultureInfo("en-GB");

  decimal val =  Decimal.Parse(currency , NumberStyles.Currency, ci.NumberFormat);

and val is number 567.3 ... no error .. tadaaa
:)

posted @ Tuesday, February 05, 2008 10:44 PM | Feedback (1) |