开发者

Thousands separator in .Net/F#

开发者 https://www.devze.com 2023-01-02 11:47 出处:网络
What\'s the recommended way to print an integer with thousands separator? Best I\'ve come up with so far is

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, bu开发者_开发百科t prints zero as 00.


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.


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


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

精彩评论

暂无评论...
验证码 换一张
取 消