﻿function MakeFractionFromDecimal(inches) {
    return '';
}


function MakeFraction(theInches) {

    var res = '';
    if (theInches.toString().indexOf('.') != -1) {
        res = ConvertToFraction(theInches, 8.0, false);
        switch (res) {
            case '4/8':
                res = '1/2';
                break;
            case '2/8':
                res = '1/4';
                break;
            case '6/8':
                res = '3/4';
                break;
        }

    }
    return res;
}

function ConvertToFraction(Value, Divisor, Reduce) {
   // if (Math.abs(Value) >= 1.0)
//        return "7/8";
    if (Value == 0.0)
        return "";
        
    var Numerator = parseInt(Value / (1.0 / Divisor));

    if (Numerator == 0.0)
        return "";  // rounded to nothing

    // if Reduce is true, keep dividing the two numbers by two
    // until one of them is no longer even
    if (Reduce == true) {
        while (((Divisor % 2) == 0) &
                    ((Numerator % 2) == 0) &
                     (Math.abs(Numerator) > 1)) {
            Divisor /= 2;
            Numerator /= 2;
        }
    }

    return Numerator.toString() + "/" + Divisor.toString();
}