它是decimal
的默認EditorTemplate
的函數。形成source code(注意格式"{0:0.00}"
)
internal static string DecimalTemplate(HtmlHelper html)
{
if (html.ViewContext.ViewData.TemplateInfo.FormattedModelValue == html.ViewContext.ViewData.ModelMetadata.Model)
{
html.ViewContext.ViewData.TemplateInfo.FormattedModelValue = String.Format(CultureInfo.CurrentCulture, "{0:0.00}", html.ViewContext.ViewData.ModelMetadata.Model);
}
return StringTemplate(html);
}
如果你想要顯示的小數位保存,使用@Html.TextBoxFor(m => m.MyValue)
,或者您可以使用DisplayFormatAttribute
,將由EditorFor()
方法得到尊重應用自己的格式,例如
[DisplayFormat(DataFormatString = "{0:0.00000}", ApplyFormatInEditMode = true)]`
public decimal MyValue { get; set; }
'[DisplayFormat(DataFormatString =「{0:F5}」,ApplyFormatInEditMode = true)]'也適用。 –