6
Reply

How to Format a String as Currency?

    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.

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

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

    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.

    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

    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