Java Utililty Methods Fraction Create

List of utility methods to do Fraction Create

Description

The list of methods to do Fraction Create are organized into topic(s).

Method

doublefrac(double number)
Gets the decimal portion of the given double.
return number - Math.floor(number);
doubleFrac(double value)
Frac
return (value - Int(value));
doublefrac(double value)
frac
return value - Math.floor(value);
doubleFrac(double x)
Fractional part of a number (y=x-|x|)
return x - Math.floor(x);
intfrac(double x)
Returns the fractional part of x, that is, the part behind the decimal dot.
return Integer.parseInt(String.valueOf(x).replaceAll("^.*\\.", ""));
floatfrac(float x)
frac
return x - trunc(x);
intfrac(int f)
frac
return (f < 0 ? -f : f) & 0xFFFF;
Stringfraction(double decimal, double tolerance)
Converts a decimal to a fraction using continued fractions.
int sign = (decimal < 0.0) ? -1 : 1;
decimal = Math.abs(decimal);
if (decimal == (int) decimal) {
    return (sign * (int) decimal + "");
double res = decimal, num = 0.0, denom = 1.0, lastdenom = 0.0, temp;
do {
    res = 1.0 / (res - (int) res);
...
doublefraction(double number)
fraction
double value = Math.IEEEremainder(Math.abs(number), 1);
if (value < 0)
    value += 1;
return value;
Stringfraction(int denominator)
fraction
switch (denominator) {
case 2:
    return "half";
case 3:
    return "third";
case 4:
    return "quarter";
case 8:
...