2017 © Pedro Peláez
 

library fraction

A composer-installable fractions library

image

spacegrass/fraction

A composer-installable fractions library

  • Saturday, June 16, 2018
  • by dallinc
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Spacegrass Fraction

Composer-installable fractions for PHP, (*1)

Usage

use Spacegrass\Fraction;

Simple Fractions

echo new Fraction(1, 2); // 1/2
echo new Fraction(5, 2); // 2 1/2

Create Fraction from string

echo Fraction::fromString('1 2/3'); // 1 2/3
echo Fraction::fromString('28/4'); // 7

Create Fraction from float

echo Fraction::fromFloat(1.5); // 1 1/2

Auto-simplified

Fractions are simplified at construction, (*2)

echo new Fraction(4, 6); // 2/3

Addition

$fraction = new Fraction(2, 7);
echo $fraction->add(new Fraction(3, 11)); // 43/77

Subtraction

$fraction = new Fraction(6);
echo $fraction->subtract(new Fraction(2, 3)); // 5 1/3

Multiplication

$fraction = new Fraction(1, 2);
echo $fraction->multiply(new Fraction(1, 2)); // 1/4

Division

$fraction = new Fraction(6, 13);
echo $fraction->divide(new Fraction(2, 7)); // 1 8/13

To Float

$fraction = new Fraction(1, 8);
$fraction->toFloat(); // 0.125

Is Integer?

Check whether a fraction is in fact a whole number., (*3)

$fraction = new Fraction(1, 8);
$fraction->isInteger(); // false

$fraction = new Fraction(16, 8);
$fraction->isInteger(); // true

Installation

run composer require spacegrass/fraction, (*4)

or, (*5)

Add package to your composer.json file, (*6)


{ "require": { "spacegrass/fraction": "dev-master" } }

The Versions

16/06 2018

dev-master

9999999-dev

A composer-installable fractions library

  Sources   Download

MIT

The Requires

  • php >=7.2.0

 

The Development Requires

by Dallin Coons

16/06 2018

1.0

1.0.0.0

A composer-installable fractions library

  Sources   Download

MIT

The Requires

  • php >=7.2.0

 

The Development Requires

by Dallin Coons