Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

System.Globalization String Format

Posted on June 24, 2015October 26, 2015 By David Kittell

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");
	}
}
Originally Posted on June 24, 2015
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code CSharp

Post navigation

Previous post
Next post

Related Posts

Save Text To File

Posted on December 14, 2013October 26, 2015

Public Function SaveTextToFile(ByVal strData As String, ByVal FullPath As String, Optional ByVal ErrInfo As String = "") As Boolean Dim Contents As String = "" Dim bAns As Boolean = False Dim objReader As StreamWriter Try objReader = New StreamWriter(FullPath) objReader.Write(strData) objReader.Close() bAns = True Catch Ex As Exception ErrInfo…

Read More

Mac OSX Terminal – Rename TTF/OTF Fonts

Posted on January 18, 2018

If you have ever received a list of fonts from a client where the font names didn’t make sense this code below will help. Caution: Backup your fonts directory just in case. #!/bin/sh # RenameFonts.sh # # # Created by David Kittell on 1/18/18. # # Use script like "sh…

Read More

Create Shortcut (VB, VB.Net, PowerShell)

Posted on December 14, 2013December 10, 2019

Sub Create_ShortCut(ByVal TargetPath As String, ByVal ShortCutPath As String, ByVal ShortCutname As String, Optional ByVal WorkPath As String = "", Optional ByVal Window_Style As Short = 0, Optional ByVal IconNum As Short = 0) Dim VbsObj As Object VbsObj = CreateObject("WScript.Shell") Dim MyShortcut As Object ShortCutPath = ShortCutPath MyShortcut =…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes