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
  • 165,109
  • 17
  • 150
  • 199
Ankit
  • 690
  • 6
  • 14

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
  • 57,903
  • 8
  • 117
  • 151
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,297
  • 3
  • 39
  • 67