用 X 位小数和 InvariantCulture 格式化数字? [英] Format a number with X decimal places and InvariantCulture?

查看:45
本文介绍了用 X 位小数和 InvariantCulture 格式化数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 ToString(CultureInfo.InvariantCulture) 格式化一个数字,并保留 5 个小数位,这可以使用 ToString("N5") 完成.我怎样才能两者兼得?

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?

推荐答案

如何使用 兼具格式和文化的重载:

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

(显然,如果您使用的是 double 替换 decimal;有 等效重载.)

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

这篇关于用 X 位小数和 InvariantCulture 格式化数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆