开发者

Find a format string for a decimal without % sign [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How to format a number as percentage without the percentage sig开发者_Go百科n?

I have a decimal:

decimal value = 0.0123m;

The format string "P" will return a string which value is multiple with 100 and add sign % at the end. Example:

string s = value.ToString("P"); // s = "1.23 %"

Please help me to find a format string without including % sign on returned string.

That mean: s will be "1.23" (without sign %)

Please help me. Thanks.


You can set the PercentSymbol property of the NumberFormatInfo to be something other than a % sign.

In your case you could just set it to be an empty string.

More info here

To do this you'll need to define a custom culture with its own NumberFormatInfo. The link to the answer provided in the comments in a great solution:

How to format a number as percentage without the percentage sign?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜