Round to 2 decimal places

Hi all,

I had a formula as follow :

Count/TotalCount*100; // in percent

whereby count is an integer and TotalCount is a double.

My result is also a double.

How can I convert the result to 2 decimal places

Thanks



Answer this question

Round to 2 decimal places

  • Ultrawhack

    Int32 Count = 10;
    Double TotalCount = 7;
    Double Output = Count / TotalCount * 100;

    // Math.Round(value, decimals)
    Console.WriteLine(Math.Round(Output, 2).ToString());

  • Round to 2 decimal places