[英]how to format 1700 to 1'700 and 1000000 to 1'000'000 in c#?
I like to format all numbers like in math. 我喜欢格式化数学中的所有数字。 is there a predefined function or is that just possible with substring and replace?
是否有预定义的函数或者是否可以使用子字符串和替换?
edit: my culture is de-ch 编辑:我的文化是de-ch
Best regards 最好的祝福
Try this 试试这个
int input = Convert.ToInt32("1700");
string result = String.Format("{0:##,##}", input);
Or this 或这个
Console.WriteLine(1700.ToString("##,##", new NumberFormatInfo() { NumberGroupSeparator = "'" }));
var numformat = new NumberFormatInfo {
NumberGroupSeparator = "'",
NumberGroupSizes = new int[] { 3 },
NumberDecimalSeparator = "."
};
Console.WriteLine(1000000.ToString("N",numformat));
Try this: 试试这个:
Console.WriteLine(1000000.ToString("#,##0").Replace(
CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, "'"));
Or 要么
NumberFormatInfo likeInMath = new NumberFormatInfo()
{
NumberGroupSeparator = "'"
};
Console.WriteLine(1000000.ToString("#,##0", likeInMath));
use int.ToString() and an iFormatProvider . 使用int.ToString()和iFormatProvider 。
I always Use this format 我总是使用这种格式
"#,##0;#,##0'-';0"
so You can use it in 所以你可以使用它
int input = Convert.ToInt32("100000000");
string result = String.Format("{#,##0;#,##0'-';0}", input);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.