将小数格式化为百分比以在视图中显示?

Tou*_*ubi 10 c# asp.net-mvc number-formatting razor

在MVC Razor视图中,十进制字段需要显示为百分比BUT而没有百分号.例如 22.5

我知道它可以来自模型,它将是这样的:

    [AutoMapIgnore]
    [DisplayFormat(DataFormatString = "{0:F1}")]
    public virtual decimal OffPeakMarginPercent { get { return OffPeakMargin * 100; } }
Run Code Online (Sandbox Code Playgroud)

但是根本没有做任何影响,目前它显示为:

目前它显示为3.000002.50000.

你能指导吗?

我高度赞赏你的指导和帮助.

编辑:

如果我在视图中格式如下,它显示为3.02.5

@row.OffPeakMarginPercent.ToString("0.0")
Run Code Online (Sandbox Code Playgroud)

Kam*_*ski 18

更改

[DisplayFormat(DataFormatString = "{0:F1}")]
Run Code Online (Sandbox Code Playgroud)

[DisplayFormat(DataFormatString = "{0:P2}")]
Run Code Online (Sandbox Code Playgroud)

并从getter中删除*100

如说这里格式百分比小数是PF