我有一个MVC2 C#.Net网络应用程序。我们希望我们的一个属性始终显示两位小数:即
.1 display as 0.10
1 display as 1.00
1.1 display as 1.10
1.21 display as 1.21
我已应用以下数据注释
[Display(Name = "Complexity/Scaling Factor")]
[DefaultValue(1.00)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:0.00}")]
[Required(ErrorMessage = "Please enter a numeric value with up to two decimal places greater than zero.")]
[RegularExpression(@"^\s*(?=.*[1-9])\d*(?:\.\d{1,2})?\s*$",
ErrorMessage = "Please enter a numeric value with up to two decimal places greater than zero.")]
public virtual double ComplexityFactor { get; set; }
...但是生成的属性无法正确显示。
2.1 displays as 2.1
1 displays as 1
想法?