public static double niceNumber(double x, boolean round) {
                // exponent of x
                int expv = (int) Math.floor(Math.log(x) / Math.log(10));
                // fractional part of x, between 1 and 10
                double f = x / Math.pow(10., expv);

                // nice, rounded fraction */
                double nf;
                if (round) {
                        if (f < 1.5) {
                                nf = 1.;
                        } else if (f < 3.) {
                                nf = 2.;
                        } else if (f < 7.) {
                                nf = 5.;
                        } else {
                                nf = 10.;
                        }
                } else if (f <= 1.) {
                        nf = 1.;
                } else if (f <= 2.) {
                        nf = 2.;
                } else if (f <= 5.) {
                        nf = 5.;
                } else {
                        nf = 10.;
                }
                return nf * Math.pow(10., expv);
        }