C# 使用DataAnnotation将小数显示为百分比
在我的数据库中,我有一个十进制值C# 使用DataAnnotation将小数显示为百分比,c#,string-formatting,data-annotations,C#,String Formatting,Data Annotations,在我的数据库中,我有一个十进制值15.0 但在我看来,它显示为1500.00% 在该属性的元数据中,我有以下内容: [Display(Name = "B Percent:")] [DisplayFormat(DataFormatString = "{0:P2}", ApplyFormatInEditMode = true)] public Nullable<decimal> BPercent { get; set; } [显示(Name=“B百分比:”)] [DisplayForm
15.0
但在我看来,它显示为1500.00%
在该属性的元数据中,我有以下内容:
[Display(Name = "B Percent:")]
[DisplayFormat(DataFormatString = "{0:P2}", ApplyFormatInEditMode = true)]
public Nullable<decimal> BPercent { get; set; }
[显示(Name=“B百分比:”)]
[DisplayFormat(DataFormatString=“{0:P2}”,ApplyFormatInEditMode=true)]
公共可为空的BPercent{get;set;}
在我看来,如何获取显示为15.0&
的值
感谢您的帮助。格式正确-
15M
实际上是1500%
。要正确显示15%
,该值必须为0.15M
。您应该将百分比值存储在0
和1
之间
如果您不能做到这一点,一个可能的解决方案是。感谢您提供指向其他问题的链接。这正是我所需要的。