Textbox 如何正确显示价格? [英] How does Textbox show price correctly?

查看:31
本文介绍了Textbox 如何正确显示价格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个Textbox来显示价格;小数如:12,000,000 OR 1 000 (Price)
使用 MaskedTextBox 我得到:120,000,00 或 100 0

I need to have a Textbox to show price; decimals like : 12,000,000 OR 1 000 (Price)
with MaskedTextBox i get : 120,000,00 OR 100 0

如果有人能提供帮助,我将不胜感激..
提前谢谢您

I would gladly appreciate it if anyone can help..
Thank You in advance

推荐答案

尝试将此代码添加到 TextBox

private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
    if (!string.IsNullOrEmpty(textBox1.Text))
    {
        System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");
        int valueBefore = Int32.Parse(textBox1.Text, System.Globalization.NumberStyles.AllowThousands);
        textBox1.Text = String.Format(culture, "{0:N0}", valueBefore);
        textBox1.Select(textBox1.Text.Length, 0);
    }
}

这篇关于Textbox 如何正确显示价格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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