c# - 字符串格式 : scale and precision from String. 格式

标签 c# .net string format

我需要格式化数字(使用 WPF 转换器),唯一的方法是通过 string.Format。

我有两个格式化参数:比例和精度。 我可以单独实现我需要的,但它不适用于两者:

示例(有效):

string.Format("{0:#,##0,,}", 1234567890.123m) == "1,235"
string.Format("{0:#,#.000}", 1234567890.123m) == "1,234,567,890.123"

我需要什么:

string.Format("????", 1234567890.123m) == "1,234.568"

(这意味着 1,234.568 百万) 如您所见,我找不到既能缩放又能显示小数的格式模式。

有什么想法吗?

最佳答案

我的一位同事得到了解决方案:

string.Format("{0:#,##0,,.000}", 1234567890.123m) == "1,234.568"

关于c# - 字符串格式 : scale and precision from String. 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11743161/

相关文章:

c# - "Access to the path ' a-guid.8Event ' is denied."启动时

.net - 使用对象属性作为字典中的键

c++ - 如何修复编译错误 "This function or variable may be unsafe"(strcpy)

java - 如何用 || 分割字符串

JavaScript:如何使用字符串作为一段代码

c# - C# 中的可空双 NaN 比较

c# - 使用ABCPDF在内存中生成文档,而不是保存在物理驱动器上

c# - 完全空白 Unity/Microsoft Store Build 未通过 WACK 测试

c# - WF4 : How do I evaluate an expression only known at runtime?

c# - 我应该默认推荐密封类吗?