public String format(Double number) {
    int sign = 1;
    if (number < 0) {
      sign = -1;
    }

    number = Math.abs(number);

    String fractionalPart = ":";

    int integerPart;

    integerPart = ((int)Math.floor(number));

    double fractional = Math.abs(number - integerPart);

    if (fractionLength < 6) {
      double minutes = fractional * 60;

      String form = "%02.0f";
      if (fractionLength == 5) {
        form = "%04.1f";
      }

      Formatter formatter = new Formatter(Locale.US);
      String newMinutes = formatter.format(form, minutes).toString();

      if (Double.parseDouble(newMinutes) >= 60.0) {
        minutes = 0.0;
        integerPart++;
      }

      formatter = new Formatter(Locale.US);
      fractionalPart += formatter.format(form, minutes);
    } else {
      double minutes = Math.floor(fractional * 60);

      double rest = fractional - ((double)minutes / 60.0);

      double seconds = rest * 3600;

      String form = "%02.0f";
      if (fractionLength == 8) {
        form = "%04.1f";
      } else if (fractionLength == 9) {
        form = "%05.2f";
      }

      Formatter formatter = new Formatter(Locale.US);
      String newSeconds = formatter.format(form, seconds).toString();

      if (Double.parseDouble(newSeconds) >= 60.0) {
        seconds = 0.0;
        minutes++;
      }

      formatter = new Formatter(Locale.US);
      String newMinutes = formatter.format("%02.0f", minutes).toString();

      if (Double.parseDouble(newMinutes) >= 60.0) {
        minutes = 0.0;
        integerPart++;
      }

      formatter = new Formatter(Locale.US);
      fractionalPart += formatter.format("%02.0f:" + form, minutes, seconds);
    }

    String res = integerPart + fractionalPart;

    if (sign < 0) {
      res = "-" + res;
    }

    res = padLeft(res, length);

    return res;
  }