Format a number with commas and decimals in C# (asp.net MVC3)
int number = 1234567890;
Convert.ToDecimal(number).ToString("#,##0.00");
You will get the result 1,234,567,890.00
.
How do I format a number in C# with commas and decimals?
Not sure (and unable to test right now) but would something like this work?
"#,##0.################"
.NET String.Format() to add commas in thousands place for a number
String.Format("{0:n}", 1234); // Output: 1,234.00
String.Format("{0:n0}", 9876); // No digits after the decimal point. Output: 9,876
Formatting Numbers as Strings with Commas in place of Decimals
I think:
string.Format(System.Globalization.CultureInfo.GetCultureInfo("de-DE"), "{0:0.0}", 4.3);
should do what you want.
Format a number with commas, but keep decimals
This appears to do exactly what you want:
public void Code(params string[] args)
{
Print(1000);
Print(100000);
Print(123.456);
Print(100000.21 );
Print(100200.123456);
}
void Print(double n)
{
Console.WriteLine("{0:###,###.#######}", n);
}
1,000
100,000
123.456
100,000.21
100,200.123456
How do I format a number with commas?
Try N0
for no decimal part:
string formatted = a.ToString("N0"); // 10,000,000
String Format for up to 2 decimal places or simple integer and with thousand separator - C#
String.Format("{0:#,##0.##}", 123.0);
Related Topics
How to Automatically Increment Numbers in C#
Linq - Groupby a Key and Then Put Each Grouped Item into Separate 'Buckets'
Epplus: Find If the Entire Row Is Empty in Excel
Programmatically Create and Launch and Rdp Session (Without Gui)
C# Adding Rows to a Datatable Inside a Foreach Loop
Using C# Lambda to Split String and Search Value
C# SQL Server Stored Procedure Parameter Return List
How to Execute Process on Remote Machine, in C#
Check If Database Exists Before Creating
How to Remove Time Portion of Date in C# in Datetime Object Only
Download File With Webclient or Httpclient
Parse Strings to Double With Comma and Point
Where Is the Postasjsonasync Method in ASP.NET Core
How to Parse Json List or Object in C#
How to Set Value of Wpf Combobox Item from C# Code