Format decimal as a percent with specific decimal places

那年仲夏 提交于 2019-12-08 16:23:08

问题


<%= Model.STPData.InitialRateSetting.HasValue ? Model.STPData.InitialRateSetting.Value.ToString() : "" %>

The Model.STPData.InitialRateSetting is a decimal. I want to format that as a percentage, and then round it to 5 decimal places. How would I do that?


回答1:


you can use

Model.STPData.InitialRateSetting.Value.ToString("P5");

assuming InitialRateSetting is a decimal




回答2:


You could use ToString("p5"). This will take the number 0.051234567 and display it as "5.12346%". I'm not sure if it'll round that last place, to make sure the behavior or lack thereof is what you want.



来源:https://stackoverflow.com/questions/5183444/format-decimal-as-a-percent-with-specific-decimal-places

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!