+
+ /**
+ * Add the given offset to the current altitude
+ * @param inOffset offset as double
+ * @param inFormat format of offset, feet or metres
+ * @param inDecimals number of decimal places
+ */
+ public void addOffset(double inOffset, Format inFormat, int inDecimals)
+ {
+ // Use the maximum number of decimal places from current value and offset
+ int numDecimals = NumberUtils.getDecimalPlaces(_stringValue);
+ if (numDecimals < inDecimals) {numDecimals = inDecimals;}
+ // Convert offset to correct units
+ double offset = inOffset;
+ if (inFormat != _format)
+ {
+ if (inFormat == Format.FEET)
+ offset = inOffset * CONVERT_FEET_TO_METRES;
+ else
+ offset = inOffset * CONVERT_METRES_TO_FEET;
+ }
+ // FIXME: The following will fail if _stringValue is null - not sure how it can get in that state!
+ if (_stringValue == null) System.err.println("*** Altitude.addOffset - how did the string value get to be null?");
+ // Add the offset
+ double newValue = Double.parseDouble(_stringValue.trim()) + offset;
+ _value = (int) newValue;
+ _stringValue = NumberUtils.formatNumber(newValue, numDecimals);
+ }