我如何在tostring格式中做两件事:
1. Display number to x decimal places
2. Also force a + sign so that negative an positive numbers lineup in nice columns.
string fmt = "+N" + dp + ";-N" + dp;
Console.WrtieLine(Open.ToString(fmt))不起作用吗?
发布于 2013-04-26 04:46:00
您需要创建一个自定义格式字符串来执行您想要的操作。http://msdn.microsoft.com/en-us/library/0c899ak8.aspx会告诉你这些,但下面是一个简单的例子,说明了其中一件事。
double num = 1111.019123;
int dp = 2;
string format = String.Format("+#.{0};-#.{0}",new string ('#',dp));
Console.WriteLine(num.ToString(format));https://stackoverflow.com/questions/16224170
复制相似问题