Android Utililty Methods Unit Convert

List of utility methods to do Unit Convert

Description

The list of methods to do Unit Convert are organized into topic(s).

Method

doubleconvertUnits(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));
...
CharSequenceformatHeartRate(int bpm)
format Heart Rate
return FORMAT_HEART_RATE.format(bpm);
CharSequenceformatHeartRate(int bpm, boolean withUnit)
format Heart Rate
String unit = "";
if (withUnit)
    unit = " bpm";
return FORMAT_HEART_RATE.format(bpm) + unit;
floatconvertLength(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");
StringconvertToPerHour(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);
floatconvertBarometricPressure(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");
floatconvertFromHgInchToHpa(float hgInch)
convert From Hg Inch To Hpa
float conversionFactor = 33.8638866667f;
return hgInch * conversionFactor;
floatconvertFromHpaToHgInch(float hpa)
convert From Hpa To Hg Inch
float conversionFactor = 33.8638866667f;
return hpa / conversionFactor;
floatconvertFromInchToMillimetre(float length)
convert From Inch To Millimetre
return length * 25.4f;
floatconvertFromMillimetreToInch(float length)
convert From Millimetre To Inch
return length * 0.0393700787f;