<?php
echo whole_fraction(23.54);
function whole_fraction($decimal){
$big_fraction = float2rat($decimal);
($numerator, $denomenator) = explode('/', $big_fraction);
$whole_number = floor($numerator/$decimal_number);
$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";
}
- Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.34
- Parse error: syntax error, unexpected ',' in /in/PAHtl on line 8
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
- Parse error: parse error, unexpected ',' in /in/PAHtl on line 8
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error in /in/PAHtl on line 8
Process exited with code 255.
preferences:
221.07 ms | 1395 KiB | 124 Q