Android Speed Readable Format speedToPace(float speedInMetersPerSecond, boolean imperial)

Here you can find the source of speedToPace(float speedInMetersPerSecond, boolean imperial)

Description

speed To Pace

License

Open Source License

Declaration

public static String speedToPace(float speedInMetersPerSecond,
            boolean imperial) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static final float ratio = 1.609344f;

    public static String speedToPace(float speedInMetersPerSecond,
            boolean imperial) {
        if (speedInMetersPerSecond <= 0) {
            return "0:00";
        }/* w  w  w.j a va2s .c  o m*/
        float speedPerHour = speedInMetersPerSecond / 1000 * 60 * 60;
        if (imperial) {
            speedPerHour = speedPerHour / ratio;
        }
        float pacePerMinute = 60 / speedPerHour;
        long minutes = (long) Math.floor(pacePerMinute);
        long seconds = Math.round((pacePerMinute - minutes) * 60);
        return String.format("%02d:%02d", minutes, seconds);
    }
}

Related

  1. speedToKMH(double kmh)
  2. speedToMPH(double kmh)
  3. convertSpeed(float speed, int fromScale, int toScale)