Recently I was asked to format a string into a different format, after some discussion they wanted the integer 500000 to show in a format attributed to India that looks like 5,00,000
The code below shows how best to convert the number, to see the code in action go to https://dotnetfiddle.net/57rggj
using System; public class Program { public static void Main() { //Reference: http://www.c-sharpcorner.com/UploadFile/0f68f2/converting-a-number-in-currency-format-for-different-culture/ int nNumber = 500000; string sText = string.Format("{0:#,###0}", nNumber); // 5,00,00 Console.Write("String.Format: " + sText + Environment.NewLine); Console.WriteLine("n--------- Globalization - Start ---------------n"); //For Current Culture Console.WriteLine("nCurrent Culture:n"); // By default, single letter C displays currency upto two decimal digits Console.WriteLine(nNumber.ToString("C", System.Globalization.CultureInfo.CurrentCulture)); // C2 displays currency upto two digits Console.WriteLine(nNumber.ToString("C2", System.Globalization.CultureInfo.CurrentCulture)); // C3 displays currency upto three digits Console.WriteLine(nNumber.ToString("C3", System.Globalization.CultureInfo.CurrentCulture)); // C4 displays currency upto four digits Console.WriteLine(nNumber.ToString("C4", System.Globalization.CultureInfo.CurrentCulture)); // C5 displays currency upto five digits Console.WriteLine(nNumber.ToString("C5", System.Globalization.CultureInfo.CurrentCulture)); Console.WriteLine("nUSA:n"); Console.WriteLine(nNumber.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("en-us"))); Console.WriteLine("nDenmark:n"); Console.WriteLine(nNumber.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("da-DK"))); Console.WriteLine("nIndia:n"); Console.WriteLine(nNumber.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("en-IN"))); Console.WriteLine("nSpanish (Spain):n"); Console.WriteLine(nNumber.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("es-ES"))); Console.WriteLine("nChinese (Taiwan):n"); Console.WriteLine(nNumber.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("zh-TW"))); Console.WriteLine("nChinese (PRC):n"); Console.WriteLine(nNumber.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("zh-CN"))); Console.WriteLine("nChinese (Hong Kong SAR):n"); Console.WriteLine(nNumber.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("zh-HK"))); Console.WriteLine("nChinese (Singapore):n"); Console.WriteLine(nNumber.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("zh-SG"))); Console.WriteLine("nChinese (Macao SAR):n"); Console.WriteLine(nNumber.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("zh-MO"))); Console.WriteLine("nJapanese (Japan):n"); Console.WriteLine(nNumber.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("ja-JP"))); Console.WriteLine("nKorean (Korea):n"); Console.WriteLine(nNumber.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("ko-KR"))); Console.WriteLine("nGerman (Germany):n"); Console.WriteLine(nNumber.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("de-DE"))); Console.WriteLine("nHungarian (Hungary):n"); Console.WriteLine(nNumber.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("hu-HU"))); Console.WriteLine("nGeorgian (Georgia):n"); Console.WriteLine(nNumber.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("ka-GE"))); Console.WriteLine("n--------- Globalization - Stop ---------------n"); } }
Last Updated on October 26, 2015