To manage the thousands separator, you must apply your changes to NumberFormat for the current culture.
If you want this to happen regardless of the current culture, you can simply clone the current culture, apply the modified NumberFormat and set it as the current one.
In an MVC application, you usually do this during Application_BeginRequest
protected void Application_BeginRequest(object sender, EventArgs e) { newCulture = (CultureInfo)CultureInfo.CurrentCulture.Clone(); newCulture.NumberFormat.NumberGroupSeparator = "~"; System.Threading.Thread.CurrentThread.CurrentCulture = newCulture; System.Threading.Thread.CurrentThread.CurrentUICulture = newCulture; }
Now you can use the ToString () "normal" formatting options to further control the formatting to suit your needs:
var a = 3000.5; var s = a.ToString('N:2')
asi
source share