News

Statistics

Locations of visitors to this page

Personal


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
:)
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Comments

Gravatar # re: Convert Currency string back to decimal
Posted by Nikkie on 10/19/2009 4:47 PM
Thanks for posting this :)
Gravatar # re: Convert Currency string back to decimal
Posted by Ven on 12/2/2009 1:07 PM
Thanks a lot for this nice post. Keep it up.
Gravatar # re: Convert Currency string back to decimal
Posted by raakesh tomar on 7/14/2011 5:53 PM
Its save me lot of time.
Thanks.
Its very simple and impressive.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: