【问题标题】:Int custom ToStringInt 自定义 ToString
【发布时间】:2017-04-15 12:01:22
【问题描述】:

我想将 UInt32 打印为 ##,##,##。
逗号每两位数。
有没有办法做到这一点?

ToString("N0");  

每三位是逗号

【问题讨论】:

标签: c# .net formatting int


【解决方案1】:

你应该可以使用(using System.Globalization;):

yourUInt.ToString("N0", new NumberFormatInfo { NumberGroupSizes = new[] { 2, }, })

文档:NumberGroupSizes property


当然,这个NumberGroupSizes 属性也可以在CultureInfoNumberFormat 属性上设置(可能通过克隆现有的只读CultureInfo 获得),然后可以将其分配给System.Threading.Thread.CurrentThread.CurrentCulture

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-10
    • 1970-01-01
    • 1970-01-01
    • 2011-06-29
    • 2019-01-02
    • 1970-01-01
    相关资源
    最近更新 更多