C#格式化文本框用逗号整数并使用Double [英] C# Format textbox Integer with comma and using Double

查看:102
本文介绍了C#格式化文本框用逗号整数并使用Double的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以用文本框帮我吗?我有textbox1,我只输入数字,我想在Text_Leave事件后将其格式化为数字:



Hi, can someone help me with textbox? i got textbox1 and i only input numbers, i wanted to format it to numbers after Text_Leave Event:

For Example :
I input 122333

Output must be:
122,333.00





这是我在text_leave中的代码



here's my code in text_leave

string a;
           double bb = double.Parse(textBox1.Text);

  a = Double.ToString("#,0.##");





textbox.Text中的输出变为#,0。##



请帮忙谢谢!



The output in textbox.Text became #,0.##

Please help Thanks!

推荐答案

尝试:

Try:
string a;
double bb;
if (!double.TryParse(textBox1.Text, out bb))
   {
   // Report a problem to the user.
   ...
   }
else
   {
   a = bb.ToString("#,000.00");
   ...


尝试 string.Format({0:n0},bb);


我想你会在MSDN上找到你需要的帮助阅读信息:自定义数字格式字符串 [ ^ ]



这还取决于您在计算机上的本地化设置。
I think you will find the help you need reading the info on MSDN: Custom Numeric Format Strings[^]

It also depends on the localization setting you have on your computer.


这篇关于C#格式化文本框用逗号整数并使用Double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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