Reputation: 3292
So I know my calculations may be large. However, when I try to do calculate the input cubed of the textbox adjacent to it, it won't display the number but it will display the string "exp: ".
Is this concatenation not working? Instead, it's only displaying "EXP: " if it's too large.
Also, I tried it the other way around but it will display the number (even if it's large) but not " exp".
for (int i = 0; i < textBoxes.Length; i++)
{
totalExp += Math.Pow(Convert.ToDouble(textBoxes[i].Text), 3.0) + 1;
labels[i].Text = "Exp: " + (Math.Pow(Convert.ToDouble(textBoxes[i].Text), 3.0) + 1).ToString("#,###.#####");
}
The textbox properties were set on my last question (https://stackoverflow.com/a/20406828/2804613)
I did the exact same thing with the labels so that they are on the right side of the textbox.
Upvotes: 0
Views: 372
Reputation: 531
Explaining my comment:
for (int i = 0; i < textBoxes.Length; i++)
{
var exp = Math.Pow(Convert.ToDouble(textBoxes[i].Text), 3.0) + 1;
totalExp += exp;
labels[i].Text = "Exp: " + exp.ToString("#,###.#####");
}
Better way to do this is using String.Format()
for (int i = 0; i < textBoxes.Length; i++)
{
var exp = Math.Pow(Convert.ToDouble(textBoxes[i].Text), 3.0) + 1;
totalExp += exp;
labels[i].Text = String.Format("Exp: {0:#,###.#####}", exp);
}
And make sure you set AutoSize
property of the label to True
.
Upvotes: 1
Reputation: 6060
I tried to reproduce your problem using the following code:
double thisExp = Math.Pow(Convert.ToDouble("1.37"), 3.0) + 1;
// totalExp += thisExp;
string Text = "Exp: " + thisExp.ToString("#,###.#####");
Console.WriteLine(Text);
It prints
Exp: 3.57135
You can try it out here
It is therefore not a formatting problem. I suspect the conversion from string to double, but we need more information for that. Especially locale settings and the exact string contents.
A second thought: Can you read back the label text? If you set the label size too narrow for the text, it may just display the first few characters.
Upvotes: 2