Format decimal for percentage values?

前端 未结 5 692
别跟我提以往
别跟我提以往 2020-11-28 23:17

What I want is something like this:

String.Format(\"Value: {0:%%}.\", 0.8526)

Where %% is that format provider or whatever I am looking for

5条回答
  •  Happy的楠姐
    2020-11-28 23:41

    I have found the above answer to be the best solution, but I don't like the leading space before the percent sign. I have seen somewhat complicated solutions, but I just use this Replace addition to the answer above instead of using other rounding solutions.

    String.Format("Value: {0:P2}.", 0.8526).Replace(" %","%") // formats as 85.26% (varies by culture)
    

提交回复
热议问题