public static double roundToSignificantNumbers(double x, int precision) {
        if (x == 0) {
            return 0;
        }
        if (x < 0) {
            return -roundToSignificantNumbers(-x, precision);
        }
        double lowerLimit = MathLib.ipow(10.0, precision - 1);
        double upperLimit = lowerLimit * 10.0;
        double multiplier = 1.0;
        while (multiplier * x < lowerLimit) {
            multiplier *= 10.0;
        }
        while (multiplier * x >= upperLimit) {
            multiplier /= 10.0;
        }
        return round(x * multiplier) / multiplier;
    }
Rounds to keep <em>precision</em> decimals. Rounds towards even numbers.
@param x the number to round
@param precision the precision to round to. A precision of 3 will for instance round 1.65432 to 1.654
@return the rounded number
main/src/main/java/cgeo/geocaching/wherigo/kahlua/stdlib/MathLib.java