C#中用逗号计算千位分隔符 [英] Calculator thousand separator by comma in C#

查看:158
本文介绍了C#中用逗号计算千位分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void TextBox_TextChanged(object sender, EventArgs e)
    {
    string value = TextBox.Text.Replace(",", "");
    long ul;
    if (long.TryParse(value, out ul))
    {
        TextBox.TextChanged -= TextBoxTextChanged;
        TextBox.Text = string.Format("{0:#,#0}", ul);
        TextBox.SelectionStart = TextBox.Text.Length;
        TextBox.TextChanged += TextBoxTextChanged;
    }
}





我上面用代码制作计算器。我想得到的结果是



按小数值等于逗号。通常我可以在textBox中键入



1,234.1234但如果我按1,000.123 + 1,000.123



它不会给出结果2,000.246 - 它只给出结果



2000.246。我的意思是逗号有十进制值没有得到



紧迫等于。



有谁可以请帮助我解决这个问题?



我尝试过:



我用于制作计算器的上述代码。我想得到的结果是



按小数值等于逗号。通常我可以在textBox中键入



1,234.1234但如果我按1,000.123 + 1,000.123



它不会给出结果2,000.246 - 它只给出结果



2000.246。我的意思是逗号有十进制值没有得到



紧迫等于。



有谁可以请帮助我解决这个问题?



I used above code for making Calculator. I want to get result by

pressing equal comma with decimal value. Normally I can type

1,234.1234 in the textBox but if I press 1,000.123 + 1,000.123

it does not give the result 2,000.246 - it gives result only

2000.246. I mean comma with decimal value not getting by

pressing equal.

Can anybody kindly please help me to solve this problem ?

What I have tried:

I used above code for making Calculator. I want to get result by

pressing equal comma with decimal value. Normally I can type

1,234.1234 in the textBox but if I press 1,000.123 + 1,000.123

it does not give the result 2,000.246 - it gives result only

2000.246. I mean comma with decimal value not getting by

pressing equal.

Can anybody kindly please help me to solve this problem ?

推荐答案

string whatYouWant = number.ToString("#,##0");







String.Format("{0:n}", 1234);

string.Format("{0:n0}", 9876); // no digits after the decimal point.





格式化您的输出值。


这篇关于C#中用逗号计算千位分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆