@ 2014-10-31T23:37:06Z <?php
echo whole_fraction(23.54);
function whole_fraction($decimal){
$big_fraction = float2rat($decimal);
$num_array = explode('/', $big_fraction);
echo $big_fraction;
$numerator = $num_array[0];
$denomenator = $num_array[1];
$whole_number = floor( $numerator / $denominator );
$numerator = $numerator % $denomenator;
$fraction = $whole_number . ' ' . $numerator . '/' . $denomenator;
}
function float2rat($n, $tolerance = 1.e-6) {
$h1=1; $h2=0;
$k1=0; $k2=1;
$b = 1/$n;
do {
$b = 1/$b;
$a = floor($b);
$aux = $h1; $h1 = $a*$h1+$h2; $h2 = $aux;
$aux = $k1; $k1 = $a*$k1+$k2; $k2 = $aux;
$b = $b-$a;
} while (abs($n-$h1/$k1) > $n*$tolerance);
return "$h1/$k1";
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 1177/50
Warning: Undefined variable $denominator in /in/VuIqJ on line 12
Fatal error: Uncaught DivisionByZeroError: Division by zero in /in/VuIqJ:12
Stack trace:
#0 /in/VuIqJ(2): whole_fraction(23.54)
#1 {main}
thrown in /in/VuIqJ on line 12
Process exited with code 255 . Output for 5.0.4 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.38 , 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.31 , 7.4.0 - 7.4.33 1177/50
Notice: Undefined variable: denominator in /in/VuIqJ on line 12
Warning: Division by zero in /in/VuIqJ on line 12
Output for 7.3.32 - 7.3.33 1177/50
Warning: Division by zero in /in/VuIqJ on line 12
Output for 4.3.0 - 4.3.11 , 4.4.0 - 4.4.9 , 5.0.0 - 5.0.3 1177/50
Notice: Undefined variable: denominator in /in/VuIqJ on line 12
Warning: Division by zero in /in/VuIqJ on line 12
preferences:dark mode live preview
342.69 ms | 402 KiB | 451 Q