![](/img/trans.png)
[英]String.Format an integer to use a thousands separator with decimal value in danish culture
[英]String.Format an integer to use a thousands separator without decimal places or leading 0 for small integers
愚蠢的問題,我想格式化一個整數,使其以 1000 的分隔符 (,) 出現,但也沒有小數位和前導 0。
到目前為止,我的嘗試是:
String.Format("{0} {1}", 5, 5000); // 5 5000
String.Format("{0:n} {1:n}", 5, 5000); // 5.00 5,000.00
String.Format("{0:0,0} {1:0,0}", 5, 5000); // 05 5,000
我追求的輸出是:
5 5,000
有什么明顯的我遺漏了嗎?
這對我有用。
String.Format("{0:#,0} {1:#,0}", 5, 5000); // 5 5,000
試試這個:-
String.Format("{0:n0}",5000) // 5,000
String.Format("{0:n0}",5) // 5
String.Format("{0:n0}",0) // 0
String.Format("{0:#,0} {1:#,0}", 5, 5000); // "5 5,000"
0
表示放置屬於此處的數字,或者[前導/尾隨]為零[以使對齊等等]。 編輯:你肯定希望一個作為模式中的最后一個數字,或者零值將呈現為空字符串 #
表示除非此處有重要數字,否則不要將任何內容放入輸出中。 編輯(感謝@eulerfx):
0
而不是#
(正如我最初的那樣),因為值為零否則將呈現為零長度字符串。 嘗試
String.Format("{0:#,#}", 4000);
這也有效:
40000.ToString("#,#")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.