static String formatDouble(double x, int just, int width, int dec) {
		int sign = 1;
		if (x < 0) {
			sign = -1;
			x = -x;
		}

		double pow10 = 1;
		for (int i = 0; i < dec; i++) {
			pow10 *= 10;
		}

		double y = Math.round(pow10 * x) / pow10;

		String s = "" + y;
		int i = s.indexOf('.');
		int l = s.length();
		if (i < 0) {
			s = s + ".";
		}
		i = s.indexOf('.');

		if (l - i - 1 < dec) {
			for (int j = l - i; j <= dec; j++) {
				s = s + "0";
			}
		} else if (l - i - 1 > dec) {
			s = s.substring(0, i + dec + 1);
		}

		if (sign < 0) {
			s = "-" + s;
		}

		while (s.length() < width) {
			if (just < 0) {
				s = s + " ";
			} else {
				s = " " + s;
			}
		}

		return s;
	}