这可能是一个简单的问题,我敢肯定有办法做到这一点的string.format(),NumberFormatInfo,CultureInfo或它们的组合,但我需要3个尾随小数显示大数值,小数,而不是为成千上万的一个逗号分隔符,然后是数百万分隔符和以上的逗号.
输入是整数或数字后跟最多三位小数(20000,123.456,12.2)
例如:
142650应显示为142,650.000
11200.50应显示为11,200.500
123.456应保持123.456
我认为这与将值除以1000然后使用相同string.format("{0:f3}", value),但我希望找到一些不采用算术的东西.
String.Format("{0:#,#.000}", value) 让我接近,但它在小数字上排名0,所以1.256显示为01.256,当我需要它只保持1.256
我想传递一个Dictionary动态设置变量,而不是对类构造函数进行大量重载.
// Class definition
public class Project
{
public DateTime LastModified;
public string LoanName;
public string LoanNumber;
public int LoanProgram;
public string ProjectAddress;
...
// Project class constructor
public Project(Dictionary<string, object> Dict)
{
foreach (KeyValuePair<string, object> entry in Dict)
{
// ie, when the Key is "LoanName", this.LoanName is set
this.(entry.Key) = entry.Value; // <-- Does not compile, obviously
}
}
}
// application code
...
Dictionary<string, object> dict = new Dictionary<string,object>();
dict.Add("LoanName", "New Loan Name");
dict.Add("LoanProgram", 1); …Run Code Online (Sandbox Code Playgroud)