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
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
Try adding this code to KeyUp
event handler of your 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);
}
}
You can use DecimalFormat
like this :
Double number = Double.valueOf(text);
DecimalFormat dec = new DecimalFormat("#.00 EUR");
String credits = dec.format(number);
TextView tt = (TextView) findViewById(R.id.creditsView);
tt.setText(credits);
Also, check this Link
Hope it will help you!
decimal a = 12000000;
Console.WriteLine(a.ToString());
//output=> 12000000
Console.WriteLine(a.ToString("N"));
//output=>12,000,000.00
Console.WriteLine(a.ToString("N1"));
//output=>12,000,000.0
Console.WriteLine(a.ToString("N0"));
//output=>12,000,000