locked
calculate using divided RRS feed

  • Question

  • User932259438 posted

    Hi,

    I'm try to make one example for calculate a/b but not working.

      double div = 1000 / 10000;

            lblBalance.Text = div.ToString();


    In this case must return: 0.1, but I got 0.

    How can I resolved this?

    Thursday, December 14, 2017 2:02 PM

Answers

  • User2103319870 posted

    progy85

    double div = 1000 / 10000;

    Even though you have the result variable as double. You are trying to divide an integer numbers. Convert the input value to double and it will work

    double div = Convert.ToDouble(1000) / Convert.ToDouble(10000); \\Return 0.1

    Sample Working Demo

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 14, 2017 2:47 PM

All replies

  • User-1716253493 posted

    Try format like this

    lblBalance.Text = div.ToString("N2");
    lblBalance.Text = div.ToString("{0:N1}");
    Thursday, December 14, 2017 2:05 PM
  • User932259438 posted

    I was trying this not working.

    Thursday, December 14, 2017 2:22 PM
  • User2103319870 posted

    progy85

    double div = 1000 / 10000;

    Even though you have the result variable as double. You are trying to divide an integer numbers. Convert the input value to double and it will work

    double div = Convert.ToDouble(1000) / Convert.ToDouble(10000); \\Return 0.1

    Sample Working Demo

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 14, 2017 2:47 PM
  • User932259438 posted

    thanks

    Thursday, December 14, 2017 4:54 PM