android - Convert min per km to display on TextView -


i developing run tracker app, calculated average pace gives me minute per km time. cant understand how convert value show in format 00:00.

this relevant method:

    private void setpace(double distanceinmeters) {     double totaltimeinsec = (timer.gettimeinseconds() + (timer.min * 60));     double meterspersecond = (distanceinmeters / totaltimeinsec);     double minperkm = 16.6666667 / meterspersecond;     // convert minperkm } 

the values gives me example duration time: 00:13:07 , distance of 2.02:

  • totaltimeinsec = 787.0
  • meterspersecond = 2.5607004323181384
  • minperkm = 6.508635875424163

i need convert minperkm real time show in average pace. can please?

found solution! corrected code, maybe anyone:

    private void setpace(double distanceinmeters) {     double totaltimeinsec = (timer.gettimeinseconds() + (timer.min * 60));     double meterspersecond = (distanceinmeters / totaltimeinsec);     double minperkm = 16.6666667 / meterspersecond;     double secondsperkm = minperkm * 60;     int sec = (int)(secondsperkm);     int min = sec / 60;     sec %= 60;     log.d("pace","your pace is: " + string.format("%02d",min) + ":" + string.format("%02d",sec));     // convert minperkm } 


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -