code: private static UnitValue temperature(UnitValue value, Unit target) {
      BigDecimal n = value.amount();
      if (target == Unit.TEMPERATURE_GENERIC) {
        return new UnitValue(n, Unit.TEMPERATURE_GENERIC);
      }
  
      switch (value.unit()) {
        case FAHRENHEIT:
          if (target == Unit.CELSIUS) {
              n = n.subtract(THIRTY_TWO);
              n = new Rational(n, BigDecimal.ONE).multiply(FIVE_NINTHS).compute(RoundingMode.HALF_EVEN);
          } else if (target == Unit.KELVIN) {
              n = n.add(KELVIN_FAHRENHEIT);
              n = new Rational(n, BigDecimal.ONE).multiply(FIVE_NINTHS).compute(RoundingMode.HALF_EVEN);
          }
          break;
          
        case CELSIUS:
          if (target == Unit.FAHRENHEIT) {
            Rational r = new Rational(n, BigDecimal.ONE);
            n = r.multiply(NINE_FIFTHS).compute(RoundingMode.HALF_EVEN).add(THIRTY_TWO);
          } else if (target == Unit.KELVIN) {
            n = n.add(KELVIN_CELSIUS);
          }
          break;
          
        case KELVIN:
          if (target == Unit.CELSIUS) {
            n = n.subtract(KELVIN_CELSIUS);
          } else if (target == Unit.FAHRENHEIT) {
            Rational r = new Rational(n, BigDecimal.ONE).multiply(NINE_FIFTHS);
            n = r.compute(RoundingMode.HALF_EVEN).subtract(KELVIN_FAHRENHEIT);
          }
          break;
          
        default:
          return new UnitValue(n, Unit.TEMPERATURE_GENERIC);
      }
  
      return new UnitValue(n.stripTrailingZeros(), target);
    }
docs: Temperature conversions.