List of utility methods to do Unit Convert
double | convertUnits(double value, String oldUnits, String newUnits) convert Units BigDecimal v = BigDecimal.valueOf(value); BigDecimal r = v; if (oldUnits.equals(UNITS_M) && newUnits.equals(UNITS_FT)) { r = v.multiply(BigDecimal.valueOf(FT_IN_M)); } else if (oldUnits.equals(UNITS_M) && newUnits.equals(UNITS_YD)) { r = v.multiply(BigDecimal.valueOf(YD_IN_M)); } else if (oldUnits.equals(UNITS_M) && newUnits.equals(UNITS_MI)) { r = v.multiply(BigDecimal.valueOf(MI_IN_M)); ... |
CharSequence | formatHeartRate(int bpm) format Heart Rate return FORMAT_HEART_RATE.format(bpm);
|
CharSequence | formatHeartRate(int bpm, boolean withUnit) format Heart Rate String unit = ""; if (withUnit) unit = " bpm"; return FORMAT_HEART_RATE.format(bpm) + unit; |
float | convertLength(float length, int fromScale, int toScale) convert from one unit of length to another switch (fromScale) { case MILLIMETRE: switch (toScale) { case INCH: return convertFromMillimetreToInch(length); default: throw new IllegalArgumentException("invalid to scale"); case INCH: switch (toScale) { case MILLIMETRE: return convertFromInchToMillimetre(length); default: throw new IllegalArgumentException("invalid to scale"); default: throw new IllegalArgumentException("invalid from scale"); |
String | convertToPerHour(float speedInMetersPerSecond, boolean imperial) convert To Per Hour float speedPerHour = speedInMetersPerSecond / 1000 * 60 * 60; if (imperial) { speedPerHour = speedPerHour / ratio; return String.format("%02.02f", speedPerHour); |
float | convertBarometricPressure(float pressure, int fromScale, int toScale) convert from one unit of barometric pressure to another switch (fromScale) { case HPA: switch (toScale) { case HG_INCH: return convertFromHpaToHgInch(pressure); default: throw new IllegalArgumentException("invalid toScale"); case HG_INCH: switch (toScale) { case HPA: return convertFromHgInchToHpa(pressure); default: throw new IllegalArgumentException("invalid toScale"); default: throw new IllegalArgumentException("invalid fromScale"); |
float | convertFromHgInchToHpa(float hgInch) convert From Hg Inch To Hpa float conversionFactor = 33.8638866667f; return hgInch * conversionFactor; |
float | convertFromHpaToHgInch(float hpa) convert From Hpa To Hg Inch float conversionFactor = 33.8638866667f; return hpa / conversionFactor; |
float | convertFromInchToMillimetre(float length) convert From Inch To Millimetre return length * 25.4f;
|
float | convertFromMillimetreToInch(float length) convert From Millimetre To Inch return length * 0.0393700787f;
|