Decimal format in the textbox Text Change C# (1000000 -> 1,000,000)
-
Have you asked yourself in the currency format function TextChange how my example below the cursor does not focus on the No. 2 spot, the book help me thanks! if (textBox1.Text == "") return; else { int iIndex = textBox1.Text.IndexOf('.'); if (iIndex == -1) { } else { string strT = textBox1.Text.Substring(iIndex + 1, 1); if (textBox1.Text != "") { } } double a = double.Parse(textBox1.Text.Trim(',')); textBox1.Text = a.ToString("#,###"); }
-
Have you asked yourself in the currency format function TextChange how my example below the cursor does not focus on the No. 2 spot, the book help me thanks! if (textBox1.Text == "") return; else { int iIndex = textBox1.Text.IndexOf('.'); if (iIndex == -1) { } else { string strT = textBox1.Text.Substring(iIndex + 1, 1); if (textBox1.Text != "") { } } double a = double.Parse(textBox1.Text.Trim(',')); textBox1.Text = a.ToString("#,###"); }
Sorry, but that doesn't make much sense. When you post code, please use the
code
widget above the textbox - it preserves formatting which makes the whole thing more readable. I have reformatted your code, and also refactored it to make it more readable - taking out redundant conditions and so forth:if (textBox1.Text != "") { int iIndex = textBox1.Text.IndexOf('.'); if (iIndex != -1) { string strT = textBox1.Text.Substring(iIndex + 1, 1); } double a = double.Parse(textBox1.Text.Trim(',')); textBox1.Text = a.ToString("#,###"); }
The trouble is that I have no idea what you are trying to do, so I also have no idea what problem you are trying to get help with! Please try to explain a bit better so we can help you.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
Have you asked yourself in the currency format function TextChange how my example below the cursor does not focus on the No. 2 spot, the book help me thanks! if (textBox1.Text == "") return; else { int iIndex = textBox1.Text.IndexOf('.'); if (iIndex == -1) { } else { string strT = textBox1.Text.Substring(iIndex + 1, 1); if (textBox1.Text != "") { } } double a = double.Parse(textBox1.Text.Trim(',')); textBox1.Text = a.ToString("#,###"); }
Not sure what you want to do. Perhaps:
int amount;
if (int.TryParse(textBox1.Text, out amount))
{
textBox1.Text=amount.ToString("#,###");
} -
Sorry, but that doesn't make much sense. When you post code, please use the
code
widget above the textbox - it preserves formatting which makes the whole thing more readable. I have reformatted your code, and also refactored it to make it more readable - taking out redundant conditions and so forth:if (textBox1.Text != "") { int iIndex = textBox1.Text.IndexOf('.'); if (iIndex != -1) { string strT = textBox1.Text.Substring(iIndex + 1, 1); } double a = double.Parse(textBox1.Text.Trim(',')); textBox1.Text = a.ToString("#,###"); }
The trouble is that I have no idea what you are trying to do, so I also have no idea what problem you are trying to get help with! Please try to explain a bit better so we can help you.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
We now want to enter the number into the textbox, textbox itself decimal format and displays the time on that textbox. For example, enter "123456789", the textbox will appear as 123,456,789. I have a problem when entering a string from 1 to 9 are ok, but when inserting a number in the range from 1 to 9, the textbox back to position the cursor on the first position, thanks to your help with , thank you very much. Code I wrote
private void textBox1_TextChanged(object sender, EventArgs e)
{
try
{
if (textBox1.Text != "")
{
int iIndex = textBox1.Text.IndexOf('.');
if (iIndex != -1)
{
string strT = textBox1.Text.Substring(iIndex + 1, 1);
}
double a = double.Parse(textBox1.Text.Trim(','));
if (textBox1.SelectionStart >= textBox1.Text.Length)
{
textBox1.Text = a.ToString("#,###");
textBox1.SelectionStart = textBox1.Text.Length;
}
else
{
textBox1.Text = a.ToString("#,###");
//Help?
}
}
}
catch (Exception) { MessageBox.Show("Must enter the number ."); }
} -
We now want to enter the number into the textbox, textbox itself decimal format and displays the time on that textbox. For example, enter "123456789", the textbox will appear as 123,456,789. I have a problem when entering a string from 1 to 9 are ok, but when inserting a number in the range from 1 to 9, the textbox back to position the cursor on the first position, thanks to your help with , thank you very much. Code I wrote
private void textBox1_TextChanged(object sender, EventArgs e)
{
try
{
if (textBox1.Text != "")
{
int iIndex = textBox1.Text.IndexOf('.');
if (iIndex != -1)
{
string strT = textBox1.Text.Substring(iIndex + 1, 1);
}
double a = double.Parse(textBox1.Text.Trim(','));
if (textBox1.SelectionStart >= textBox1.Text.Length)
{
textBox1.Text = a.ToString("#,###");
textBox1.SelectionStart = textBox1.Text.Length;
}
else
{
textBox1.Text = a.ToString("#,###");
//Help?
}
}
}
catch (Exception) { MessageBox.Show("Must enter the number ."); }
}Do not use the TextChanged event, LostFocus or Validating are better.
-
Have you asked yourself in the currency format function TextChange how my example below the cursor does not focus on the No. 2 spot, the book help me thanks! if (textBox1.Text == "") return; else { int iIndex = textBox1.Text.IndexOf('.'); if (iIndex == -1) { } else { string strT = textBox1.Text.Substring(iIndex + 1, 1); if (textBox1.Text != "") { } } double a = double.Parse(textBox1.Text.Trim(',')); textBox1.Text = a.ToString("#,###"); }
Mightn't a NumericUpDown be what you want?
-
Do not use the TextChanged event, LostFocus or Validating are better.
I think there are workarounds, but they have not thought out.
-
Mightn't a NumericUpDown be what you want?
Have you no one has any solution to make stars? :(
-
Have you asked yourself in the currency format function TextChange how my example below the cursor does not focus on the No. 2 spot, the book help me thanks! if (textBox1.Text == "") return; else { int iIndex = textBox1.Text.IndexOf('.'); if (iIndex == -1) { } else { string strT = textBox1.Text.Substring(iIndex + 1, 1); if (textBox1.Text != "") { } } double a = double.Parse(textBox1.Text.Trim(',')); textBox1.Text = a.ToString("#,###"); }
This big forum who can solve the problem of your own?
-
Sorry, but that doesn't make much sense. When you post code, please use the
code
widget above the textbox - it preserves formatting which makes the whole thing more readable. I have reformatted your code, and also refactored it to make it more readable - taking out redundant conditions and so forth:if (textBox1.Text != "") { int iIndex = textBox1.Text.IndexOf('.'); if (iIndex != -1) { string strT = textBox1.Text.Substring(iIndex + 1, 1); } double a = double.Parse(textBox1.Text.Trim(',')); textBox1.Text = a.ToString("#,###"); }
The trouble is that I have no idea what you are trying to do, so I also have no idea what problem you are trying to get help with! Please try to explain a bit better so we can help you.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
Thanks for your interest in my question the last few days, now I have done the above issue then. :)