Percentage decimal format with specific decimal places

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

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

+8
decimal c #
source share
2 answers

you can use

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

Assuming InitialRateSetting is Decimal

+16
source share

You can use ToString("p5") . This will take the number 0.051234567 and display it as "5.12346%". I'm not sure if this will be around this last place to make sure that the behavior or lack of it is what you want.

+3
source share

All Articles