locked
double displaying as 0.12 not 12 RRS feed

  • Question

  • User-1901014284 posted

    Hi,

    I have the below code to calculate a division on 2 textboxes based in their int values. the code runs with no issues but returns a result with 0. (for example the final result displays as 0.12 whereas I would like the result to be displayed as 12.

    double conhrs, HrsPerYear;
    double.TryParse(ContractAnnualHoursTextBox.Text, out conhrs);
    double.TryParse(HoursperYearLabel.Text, out HrsPerYear);

    double Perc = (double)conhrs / HrsPerYear;
    //if (Perc > 0)
    TotalPercentageLabel.Text = Perc.ToString("c").Remove(0, 1);

    Any help would be greatly appreciated.

    Jonny

    Friday, August 10, 2018 11:15 AM

Answers

  • User475983607 posted

    If this is a math question, multiply the percentage by 100. 

    double Perc = 100.00m * (double)conhrs / (double)HrsPerYear;

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 10, 2018 11:29 AM

All replies

  • User475983607 posted

    If this is a math question, multiply the percentage by 100. 

    double Perc = 100.00m * (double)conhrs / (double)HrsPerYear;

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 10, 2018 11:29 AM
  • User-1901014284 posted

    Worked perfectly, thank you very much :)

    Friday, August 10, 2018 1:05 PM