9
<%= 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?

slandau
  • 23,528
  • 42
  • 122
  • 184

2 Answers2

20

you can use

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

assuming InitialRateSetting is a decimal

Ta01
  • 31,040
  • 13
  • 70
  • 99
4

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.

KeithS
  • 70,210
  • 21
  • 112
  • 164