简体   繁体   English

如何在c#中格式化1700到1'700和1000000到1'000'000?

[英]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

also take a look here msdn. 另外看看这里msdn。

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.

相关问题 C#datagridview数据绑定数显示格式为10,000,000的值 - C# datagridview databound number display format for 10,000,000 value 替换出现数值的字符串 (1000000) 应采用十进制格式,如 (1,000,000.00) - Replace a string where a numeric value occurs(1000000) should be in decimal format like(1,000,000.00) C# 中值 20 000 000,50 的数据类型? - Datatype for for value of 20 000 000,50 in C#? 如何从C#中的字符串中删除\\ u000a - How to remove \u000a from a string in C# C#中1000,000格式的自定义数字组(千位分隔符) - Custom number group (thousand separator) for 1000,000 format in c# 为什么1000000不等于1000000.toString(“ N”,新的CultureInfo(“ fr-FR”)) - Why is 1 000 000 not equal to 1000000.toString(“N”, new CultureInfo(“fr-FR”)) 使用C#.NET WinForms和WPF应用程序使用自定义格式字符串将财务数据(如“ 2,000”)格式化为“ 2M” - Format Financial Data like “2,000” as “2M” using a custom Format String with C# .NET WinForms and WPF Applications 如何在超过 1,000,000,000 条记录中更改 substring? - How to change substring in more than 1,000,000,000 records? 如何使用C#将4,500,000条记录快速插入sql server数据库 - how to fast Insert 4,500,000 record into sql server database with c# 如何读取包含超过 200,000 行的大型 excel 文件并将该数据加载到 C# 中的数据表中 - How to read large excel files containing more that 200,000 rows and load that data in datatable in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM