class MathHelper {

    public static String numberToFraction(Double number) {
        String fraction = StringUtils.EMPTY;

        String sign = number >= 0 ? StringUtils.EMPTY : "-";
        number = Math.abs(number);

        int fullPart = (int) Math.floor(number);
        number = number - fullPart;

        double minMargin = 1;
        for (Entry<Double, String> fractionEntry : FRACTION_MAP.entrySet()) {

            double margin = Math.abs(fractionEntry.getKey() - number);

            if (margin < minMargin) {
                fraction = fractionEntry.getValue();
                minMargin = margin;
            }

        }

        if (number < 0.05 && number >= 0) {
            fraction = "0";
        } else if (number > 0.95 && number <= 1) {
            fraction = "1";
        }

        if (fraction.isEmpty() || number > 1 || number < 0) {
            fraction = String.valueOf(number);
        } else if (fullPart > 0) {
            if (!fraction.equalsIgnoreCase("0")) {
                fraction = fullPart + " " + fraction;
            } else {
                fraction = String.valueOf(fullPart);
            }
        }

        return sign + fraction;
    }

    private  MathHelper();

}