首页 文章

格式十进制9999,99

提问于
浏览
1

是否有格式字符串将小数格式化为000000000,00 . 所以前9位数,如果需要,右边用零填充;逗号作为分数分隔符和两个小数位 .

  • 0 => 00000000,00

  • 12 => 00000012,00

  • 987456,456 => 000987456,46

所以类似myDecimal.ToString(“D9”)和.ToString(“F2”)

3 回答

  • 3
    decimal value = 0m;
    Console.WriteLine(value.ToString("000000000.00", CultureInfo.CreateSpecificCulture("da-DK")));
    // 000000000,00
    
    value = 12m;
    Console.WriteLine(value.ToString("000000000.00", CultureInfo.CreateSpecificCulture("da-DK")));
    // 000000012,00
    
    value = 987456.456m;
    Console.WriteLine(value.ToString("000000000.00", CultureInfo.CreateSpecificCulture("da-DK")));
    // 000987456,46
    
  • 3

    你可以使用String.Format

    Dim d1 = 0D
    Dim d2 = 12D
    Dim d3 = 987456.456
    Dim d1formatted = String.Format("{0:000000000.00}", d1)
    Dim d2formatted = String.Format("{0:000000000.00}", d2)
    Dim d3formatted = String.Format("{0:000000000.00}", d3)
    

    http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

  • 2
    String.Format("{0:000000000.00}", mydouble);
    

    你会得到一个,或者 . 基于线程的当前文化设置 .

    如果您使用:

    String.Format Method (IFormatProvider, String, Object[])

    您可以设置正确的格式化程序

相关问题