1

I am trying to show the time taken by a process in label. So I implemented watch.

Now let say process took 7 miliseconds and I want to show it in seconds so I wrote 7/1000 which should be 0.007 but its showing 0.

I am showing it into label, so if any conversions of string can show this format please suggest me.

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
Ankit
  • 760
  • 6
  • 15

2 Answers2

2

You're not posting any code, but I suppose that you divide two integer values. Integer division always results in an integer as well.

If you divide 7/1000.0 instead (and/or cast at least one operand to a floating-point number, e.g. double) the division will give you the expected result.

Lucero
  • 59,176
  • 9
  • 122
  • 152
0

You are probably using an int which will not have decimal points. try and change it to a double.

The simplest fix here would be to change your calculation to

seconds/1000.0
David Pilkington
  • 13,528
  • 3
  • 41
  • 73