Santosh Kumar Adidawarpu
How to Format a String as Currency?
By Santosh Kumar Adidawarpu in .NET on Feb 11 2017
  • Santosh Kumar Adidawarpu
    Feb, 2017 11

    The standard numeric format specifier we use is the Currency (“C”) Format specifier, which is formatted like this: { 0:C } decimal value = 1234.88m;string ttl = string.Format("{ 0:C }", value); WriteLine(ttl + " \n\n"); In other way we can achieve the same result is by using ToString() function. Ex: decimal value = 1234.88m; WriteLine(value.ToString("C") + " \n\n"); ReadKey(); Using CultureInfo.CreateSpecificCulture() one can set the culture information, and thereby adjust to the country and print out the price with the proper money currency symbol.

    • 2
  • Raj Kumar
    Jun, 2017 6

    decimal moneyvalue = 1921.39m; string html = String.Format("Order Total: {0:C}", moneyvalue); Console.WriteLine(html);

    • 1
  • Chetan Raiyani
    Jun, 2017 5

    double dblAmt=134600.00;System.Globalization.CultureInfo info = System.Globalization.CultureInfo.GetCultureInfo("en-IN"); string StrAmt = dblAmt.ToString("N2", info); txtAmt.Text = StrAmt;Output := 1,34,600.00

    • 1
  • Sujeet Singh
    Jul, 2018 22

    decimal moneyvalue = 1921.39m; string html = String.Format("Order Total: {0:C}", moneyvalue); Console.WriteLine(html);

    • 0
  • Rajkiran Swain
    Jun, 2017 7

    string.Format("{0:#.00}", Convert.ToDecimal(myMoneyString) / 100);

    • 0
  • Raj Kumar
    Jun, 2017 6

    When building a string for output to a web page, it’s useful to format any currency value in a human-friendly money format. This is extremely easy in C#.The system format string works like this: {0:C}For example, the following code example:decimal moneyvalue = 1921.39m; string html = String.Format("Order Total: {0:C}", moneyvalue); Console.WriteLine(html); Outputs the following:Order Total: $1,921.39It’s worth noting that you must pass in a numeric value to the String.Format statement. If you pass in a string value, it won’t format correctly. If your currency value is in a string, you need to convert it into a double first.

    • 0
  • Chetan Raiyani
    Jun, 2017 5

    double dblAmt=134600.00;System.Globalization.CultureInfo info = System.Globalization.CultureInfo.GetCultureInfo("en-IN"); string StrAmt = dblAmt.ToString("N2", info); txtAmt.Text = StrAmt;Output := 1,34,600.00

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS