1. Go to this page and download the library: Download pbaczek/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/ */
pbaczek / fraction example snippets
use pbaczek\fraction\Fraction;
// 1/2 or 0.5
$fractionHalf = new Fraction(1, 2);
// 3/17 or 0,17647...
$fractionThreeSeventeenth = new Fraction(3, 17);
$additionResult = Fraction::from($fractionHalf);
$additionResult->add($fractionThreeSeventeenth);
// 23/34
echo $additionResult;
// 0.68
echo $additionResult->getRealValue();
use pbaczek\fraction\Fraction;
// -1/2
$negativeHalf = new Fraction(-1, 2);
// 1/2
$positiveHalf = new Fraction(1, 2);
$subtractionResult = Fraction::from($negativeHalf);
$subtractionResult->subtract($positiveHalf);
// -1
echo $subtractionResult;
// -1
echo $subtractionResult->getRealValue();
use pbaczek\fraction\Fraction;
// 2/3
$twoEleventh = new Fraction(2, 11);
$minusThreeSeventeenth = new Fraction(-3, 17);
$multiplicationResult = Fraction::from($twoEleventh);
$multiplicationResult->multiply($minusThreeSeventeenth);
// -6/187
echo $multiplicationResult;
// -0.03
echo $multiplicationResult->getRealValue();
use pbaczek\fraction\Fraction;
// 2
$two = new Fraction(2);
// 1/2
$oneHalf = new Fraction(1, 2);
$divisionResult = Fraction::from($two);
$divisionResult->divide($oneHalf);
// 4
echo $divisionResult;
// 4
echo $divisionResult->getRealValue();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.