2016-02-29 51 views
-1

我该如何添加一个逗号为double这是我的代码,但它并没有给我我想要的。任何帮助表示赞赏感谢C#如何在千位加一个逗号作为双精度?

class invoice 
{ 
    private static int invoiceNumber = 0; 
    private String customerName; 
    private double total = 0; 

    public invoice(String name, invoiceLineItem[] item) 
    { 
     invoiceNumber = invoiceNumber + 1; 
     customerName = name; 
     Console.WriteLine("Invoice Number :" + invoiceNumber); 
     Console.WriteLine(customerName); 
     Console.WriteLine("Product Number\tDescription\t Quantity\t Unit Price\tExtended Price\n"); 

     for (int i = 0; i < item.Length; i++) 
     { 
      item[i].displayItem(); 
      total = total + item[i].getExtendedPrice(); 
     } 
     Console.WriteLine("-------------------------------------------------------------------------"); 
     String.Format("{0:N} Invoice Total:           " + total);// here is where i want to add a comma to the double total 
     Console.WriteLine(""); 
    } 
+0

请向我们展示_total_此刻显示的内容以及您期望的内容。 – bkdev

回答

1

你打电话string.Format,给它格式字符串,然后在最后串联你的价值。

String.Format("{0:N} Invoice Total: " + total)应该是接近String.Format("Invoice Total: {0:N} ", total)

既然你正在处理一个货币值,使用C format可能更有意义。

请参阅string.Format的文档。

+1

没错。此外@ student45还应该使用_String.Format_的返回值:例如,'string result = String.Format(“Invoice Total:{0:N}”,total);' – bkdev

相关问题