开发者

Format a number with X decimal places and InvariantCulture?

I want to format a number using ToString(CultureInfo.InvariantCulture) and also to 5 decimal places, which 开发者_开发问答can be done using ToString("N5"). How can I do both together?


How about using the overload which takes both a format and a culture:

decimal m = 123.4567890123m;
string x = m.ToString("N5", CultureInfo.InvariantCulture);

(Obviously substitute double for decimal if you're using that; there's an equivalent overload.)


In case you have Decimal not Double:

string.Format(CultureInfo.InvariantCulture, "{0:f5}", m)

as Decimal.ToString() does not have these overloads

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜