如何在c#中将数字拆分为3位数组,不带小数符号 [英] how to Split number into groups of 3 digits in c# without decimal symbol
本文介绍了如何在c#中将数字拆分为3位数组,不带小数符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我想在c#中将数字拆分成3位数组这是我的代码:
fo_1 = int .Parse(TextBox1.Text);
TextBox1.Text = fo_1.ToString( N,CultureInfo.CreateSpecificCulture( es-ES));
< br $>
但这段代码改为1000000到1.000.000,00但是我想要1.000.000
请帮帮我
谢谢。
解决方案
您使用的是标准数字格式字符串N。如果没有精度说明符,则使用默认精度,通常为N2。请参阅标准数字格式字符串 [ ^ ]了解详情然后尝试N0 。
Alan。
然后不要尝试将其转换为特定于文化的号码。使用常规格式或创建自定义数字格式,小数点后不包含数字。请参阅 https://msdn.microsoft.com/en-us/library/ 0c899ak8(v = vs.110).aspx [ ^ ]。
fo_1 = int 跨度> .Parse(TextBox1.Text);
TextBox1.Text = fo_1.ToString( #,#,CultureInfo.InvariantCulture) ;
hi I want to Split number into groups of 3 digits in c# this is my code :
fo_1 = int.Parse(TextBox1.Text);
TextBox1.Text = fo_1.ToString("N", CultureInfo.CreateSpecificCulture("es-ES"));
but this code changes 1000000 to 1.000.000,00 but I want 1.000.000
please help me
thanks.
解决方案
You are using "N", the standard number format string. Without a precision specifier this uses the default precision which is usually "N2". See Standard Numeric Format Strings[^] for details and then try "N0".
Alan.
Then do not try to convert it to a culture specific number. Use a general format or create a custom numeric format the does not contain digits after the decimal point. See https://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx[^].
fo_1 = int.Parse(TextBox1.Text); TextBox1.Text = fo_1.ToString("#,#", CultureInfo.InvariantCulture);
这篇关于如何在c#中将数字拆分为3位数组,不带小数符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文