A
Andrus
I need to format any decimal value so that it is right aligned, thousands
are separated and shows 2 decimal places always.
I tried code below but this shows number in wrong format, "1 2 ."
How to force TextBox or MaskedTextBox display 12 as 12.00 ?
Andrus.
using System;
using System.Windows.Forms;
class Order
{
public decimal Amount { get; set; }
}
class Form1 : Form
{
static void Main()
{
Application.Run(new Form1());
}
public Form1()
{
Controls.Add(new Button() { Top = 200 });
var mtb = new MaskedTextBox();
mtb.Mask = "9,999.99";
mtb.AsciiOnly = true;
mtb.HidePromptOnLeave = true;
mtb.TextAlign = HorizontalAlignment.Right;
mtb.ValidatingType = typeof(decimal);
var ord = new Order() { Amount = 12 };
mtb.DataBindings.Add("Text", ord, "Amount");
Controls.Add(mtb);
}
}
are separated and shows 2 decimal places always.
I tried code below but this shows number in wrong format, "1 2 ."
How to force TextBox or MaskedTextBox display 12 as 12.00 ?
Andrus.
using System;
using System.Windows.Forms;
class Order
{
public decimal Amount { get; set; }
}
class Form1 : Form
{
static void Main()
{
Application.Run(new Form1());
}
public Form1()
{
Controls.Add(new Button() { Top = 200 });
var mtb = new MaskedTextBox();
mtb.Mask = "9,999.99";
mtb.AsciiOnly = true;
mtb.HidePromptOnLeave = true;
mtb.TextAlign = HorizontalAlignment.Right;
mtb.ValidatingType = typeof(decimal);
var ord = new Order() { Amount = 12 };
mtb.DataBindings.Add("Text", ord, "Amount");
Controls.Add(mtb);
}
}