Last post Jul 02, 2019 06:31 AM by Yongqing Yu
Jul 02, 2019 05:17 AM|jsshivalik|LINK
I want if value in TextBox is 22000 then it should get converted to 22000.00
Jul 02, 2019 06:31 AM|Yongqing Yu|LINK
According to your description, I suugest that you can change the input format by triggering the OnTextChanged event of the textbox control.
Note that you need to set the AutoPostBack property of the textbox to true so that you can trigger the code behind method only after the input is complete.
In the OnTextChanged event, by getting the value of textbox, you first convert it into data of double type, and then convert it into
ToString("0.00") type to change the form of textbox value.
You could refer to this link:https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings
Here is an example about this ,you could refer to the following code:
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" AutoPostBack="true"></asp:TextBox>
protected void TextBox1_TextChanged(object sender, EventArgs e)
double dtext = Convert.ToDouble(TextBox1.Text);
string stext = dtext.ToString("0.00");
TextBox1.Text = stext;
The result of this work demo: