none
Conversion Currency to Decimal Number in C#.

    Question

  • Hi,
         I have a Gross Amount text box. In that the amount is displayed as per local system currency settings. In other words the amount is displayed in Swedish Krone or US Dollar. I want to convert it to decimal number for further calculation. How Could I convert Currency to decimal number in C#. Is there any built in function to revert it back from currency to decimal in C#(System.Globalization Class).

    I would appreciate if any one answer for this.

    //Chengamkathiravan.
    Wednesday, July 02, 2008 7:43 AM

Answers

  • using System.Globalization;
    ...
          string s = "$123,456.78";
          decimal value;
          bool ok = decimal.TryParse(s, NumberStyles.Currency,
            CultureInfo.CurrentCulture.NumberFormat, out value);
          if (ok) Console.WriteLine(value);

    Output: 123456.78

    Hans Passant.
    Wednesday, July 02, 2008 10:58 AM

All replies

  • using System.Globalization;
    ...
          string s = "$123,456.78";
          decimal value;
          bool ok = decimal.TryParse(s, NumberStyles.Currency,
            CultureInfo.CurrentCulture.NumberFormat, out value);
          if (ok) Console.WriteLine(value);

    Output: 123456.78

    Hans Passant.
    Wednesday, July 02, 2008 10:58 AM
  • Hi,
     The above code is working fine to convert currency to number to both (US Dollar and Swedish Krone) . Anyways thanks for your timely help.

    //ChengamKathiravan.
    Thursday, July 03, 2008 10:26 AM