import all_constants as c def convert_distance(value, from_unit, to_unit): """ Converts a distance value from one unit to another. Uses meters as the intermediate base unit. Returns the result rounded to 4 decimal places (or int if whole number). """ # Convert to meters first, then to target unit in_meters = value * c.TO_METERS[from_unit] result = in_meters / c.TO_METERS[to_unit] # Round to 4 decimal places and strip trailing zeros rounded = round(result, 4) if rounded == int(rounded): return int(rounded) return rounded