コード例 #1
0
ファイル: Energy.java プロジェクト: TeamEel/Phase2
  /**
   * The Energy as a string, formatted to 3 decimal places with units.
   *
   * <p>As energy values can be very large, this function makes use of the kilo-, mega-, and giga-
   * prefixes
   *
   * @return string representation of the energy
   */
  @Override
  public String toString() {

    if (joules >= 10000000000.0) {
      return Format.toThreeDecimalPlaces(joules / 1000000000.0) + " GJ";
    } else if (joules >= 1000000.0) {
      return Format.toThreeDecimalPlaces(joules / 1000000.0) + " MJ";
    } else if (joules >= 1000) {
      return Format.toThreeDecimalPlaces(joules / 1000) + " kJ";
    } else {
      return Format.toThreeDecimalPlaces(joules) + " J";
    }
  }