PHP code example of lamansky / fraction

1. Go to this page and download the library: Download lamansky/fraction library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lamansky / fraction example snippets


$f = new Fraction(7, 2);
echo $f->toString(); // 3 1/2
echo $f->getMixedInteger(); // 3
echo $f->getMixedNumerator(); // 1
echo $f->getDenominator(); // 2

$f = new Fraction(5, 4);
echo $f->getNumerator(); // 5
echo $f->getMixedNumerator(); // 1

$f = new Fraction(-5, 4);
echo $f->toString(); // '-1 1/4'

$f = new Fraction(-5, 4);
echo $f->toUnicodeString(); // '−1¼'

$f = new Fraction(-5, 4);
echo $f->toFloat(); // -1.25