简体   繁体   中英

Formatting a Nullable Decimal in a Razor View in ASP.NET

I have an ASP.NET MVC app. This app is using Razor in the views. I am trying to display a 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 . Currently, I have a plain old:

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

This approach displays 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? with out the decimals.

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

Will display 567

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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