Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thousands separator in .Net/F#

Tags:

.net

f#

What's the recommended way to print an integer with thousands separator? Best I've come up with so far is

let thousands(x:int64) = String.Format("{0:0,0}", x)

Which works in most cases, but prints zero as 00.

like image 846
rwallace Avatar asked Jun 04 '10 09:06

rwallace


1 Answers

The formatting token for a decimal place in .NET is "." regardless of the culture that the assembly is using, and "," for the thousand separator. However different cultures (for example France) use "," for decimal places, so that might be an issue to consider.

Here's some (C#) examples:

C
£N
£#,#

double x = 67867987.88666;  
Console.WriteLine("{0:C}",x);  
Console.WriteLine("£{0:N}", x);  
Console.WriteLine("£{0:#,#.###}", x);  

Output:  
£67,867,987.89  
£67,867,987.89  
£67,867,987.887

More details here.

like image 97
Chris S Avatar answered Oct 13 '22 10:10

Chris S