简体   繁体   English

在ASP.NET中的Razor视图中格式化可空的十进制

[英]Formatting a Nullable Decimal in a Razor View in ASP.NET

I have an ASP.NET MVC app. 我有一个ASP.NET MVC应用程序。 This app is using Razor in the views. 该应用程序在视图中使用Razor。 I am trying to display a decimal? 我要显示decimal? . The twist on this is that I do NOT want to show decimals. 与此不同的是,我不想显示小数。 In other words, if the nullable decimal value is 567.89 , I just want to display 567 . 换句话说,如果可为空的十进制值为567.89 ,我只想显示567 Currently, I have a plain old: 目前,我的年龄很普通:

<div class="icon">@Model.Count</div>

This approach displays 567.89 . 此方法显示567.89 How do I format this nullable decimal to only show the whole number portion? 如何格式化此可为空的小数,使其仅显示整数部分?

Thank you! 谢谢!

You can use String.Format to display the decimal? 您可以使用String.Format显示小数吗? with out the decimals. 不含小数。

@String.Format("{0:0}", 567.89)

Will display 567 将显示567

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM