[英]decimal format c#
I have the following problem: i need to convert a decimal number to string.我有以下问题:我需要将十进制数转换为字符串。 Example: 11.350 (eleven thousand three hundreds fifty)
示例:11.350(一万三百五十)
code代码
lbl_valorBuyin.Text =
(Valid.GetDecimal(TORNEO.RBUYIN) +
Valid.GetDecimal(TORNEO.VALORBOUNTY)).ToString("###,###");
and the output is 11,350 and i want it to be 11.350. output 是 11,350,我希望它是 11.350。 It´s not clear for me the use of format when converting decimal values to string.
在将十进制值转换为字符串时,我不清楚格式的使用。
I have tried differents formats, but not case.我尝试过不同的格式,但不是大小写。 I couldn´t work it out.
我无法解决。
Can you help me?你能帮助我吗?
Thanks in advance.提前致谢。
Looks like Formatting numbers in different cultures看起来像在不同文化中格式化数字
Use .ToString("N2");
使用
.ToString("N2");
This will format your number using the current culture.这将使用当前文化格式化您的号码。
If you don't need decimal places use .ToString("N0");
如果您不需要小数位,请使用
.ToString("N0");
Use the following:使用以下内容:
ToString("0,###");
Refer to Decimal.ToString Method (String)参考Decimal.ToString 方法(字符串)
Try like this:试试这样:
.ToString("0.000", CultureInfo.InvariantCulture);
Try .ToString("#\\.###");
试试
.ToString("#\\.###");
I ran a little test and (11350.0).ToString("#\\.###")
gave me an output of 11.350我进行了一些测试,
(11350.0).ToString("#\\.###")
给了我一个 11.350 的 output
For a quick formatting like what you want:对于您想要的快速格式化:
.ToString("###,###", new NumberFormatInfo() { NumberGroupSeparator = "." });
It's in the IFormatProvider passed to ToString
that are defined all separators and formatting properties.它在传递给
ToString
的IFormatProvider中定义了所有分隔符和格式化属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.