3v4l.org

run code in 300+ PHP versions simultaneously
<?php $whole = floor ( $float ); $decimal = $float - $whole; $leastCommonDenom = 48; // 16 * 3; $denominators = array (2, 3, 4, 8, 16, 24, 48 ); $roundedDecimal = round ( $decimal * $leastCommonDenom ) / $leastCommonDenom; if ($roundedDecimal == 0) return $whole; if ($roundedDecimal == 1) return $whole + 1; foreach ( $denominators as $d ) { if ($roundedDecimal * $d == floor ( $roundedDecimal * $d )) { $denom = $d; break; } } return ($whole == 0 ? '' : $whole) . " " . ($roundedDecimal * $denom) . "/" . $denom; //echo toFraction( -0.5) . "\n" . toFraction( 1.5);
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined variable $float in /in/pnsXd on line 2 Deprecated: floor(): Passing null to parameter #1 ($num) of type int|float is deprecated in /in/pnsXd on line 2 Warning: Undefined variable $float in /in/pnsXd on line 3

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
42.59 ms | 405 KiB | 5 Q