C
CSharp-Jay
So I am working on my college homework for our C# class, and am kind
of stuck on something that I could use some help with. The assignment
is to create a BMI Calculator. The test data the instructor wants us
to use is a height of 63 and a weight of 140, which should output as
24.8. I've got everything down except one problem, I think when I
convert my double bmi variable to string for output, it truncates the
value and comes out as just 24, instead of 24.8. How do I set up the
formatting for my output? My code example is below, any help is
greatly appreciated, thank you
private void btnCalculateBMI_Click(object sender, EventArgs e)
{
// Declare and assign variables used for BMI Calculation.
int height, weight = 0;
double bmi = 0;
// Convert string inputs to our declared variables.
height = int.Parse(txtInputHeight.Text);
weight = int.Parse(txtInputWeight.Text);
// Perform the BMI calculation and assign it to a
variable.
bmi = 703 * weight / (height * height);
// Round off the bmi variable
Math.Round(bmi);
// Output the BMI calculation to our output label
lblOutputBMI.Text = Convert.ToString(bmi);
}
of stuck on something that I could use some help with. The assignment
is to create a BMI Calculator. The test data the instructor wants us
to use is a height of 63 and a weight of 140, which should output as
24.8. I've got everything down except one problem, I think when I
convert my double bmi variable to string for output, it truncates the
value and comes out as just 24, instead of 24.8. How do I set up the
formatting for my output? My code example is below, any help is
greatly appreciated, thank you

private void btnCalculateBMI_Click(object sender, EventArgs e)
{
// Declare and assign variables used for BMI Calculation.
int height, weight = 0;
double bmi = 0;
// Convert string inputs to our declared variables.
height = int.Parse(txtInputHeight.Text);
weight = int.Parse(txtInputWeight.Text);
// Perform the BMI calculation and assign it to a
variable.
bmi = 703 * weight / (height * height);
// Round off the bmi variable
Math.Round(bmi);
// Output the BMI calculation to our output label
lblOutputBMI.Text = Convert.ToString(bmi);
}