Android examples for java.lang:Double
Convert double To Rational
public class Main { public static void doubleToRational(double value, long[] output) { doubleToRational(value, output, 0.00001); }/*from w w w . j a v a 2s .c o m*/ private static void doubleToRational(double value, long[] output, double error) { long number = (long) value; value -= number; if (value < 0.000001 || error > 1) { output[0] = (int) (number + value + 0.5); output[1] = 1; } else { doubleToRational(1.0 / value, output, error / value); number = number * output[0] + output[1]; output[1] = output[0]; output[0] = number; } } }