php-number/php-number

An arbitrary precision for floating point Numbers for PHP

v1.2.0 2019-11-28 12:32 UTC

This package is auto-updated.

Last update: 2024-11-29 05:51:21 UTC


README

PHP from Packagist

An arbitrary precision for floating point Numbers for PHP

Add to composer

composer require cydrickn/number

Use class

use Cydrickn\Number\Number;

Global Configuration

Number::setConfig(array('places'=>20,'round'=>true));

Constructor

$num = new Number(0.1);

Methods

Plus

plus($num)

$num = number | string | Number()

Return new Number The value is the value of this Number plus to $num

$x = new Number(1.2);
$x->plus(3.2);          // 4.4

Minus

minus($num)

$num = number | string | Number()

Return new Number The value is the value of this Number minus to $num

$x = new Number(4.2);
$x->minus(3.2);          // 1

Times

times($num)

$num = number | string | Number()

Return new Number The value is the value of this Number times to $num

$x = new Number(1.2);
$x->times(2);          // 2.4

Divided By

dividedBy($num)

$num = number | string | Number()

Return new Number The value is the value of this Number divided by to $num

$x = new Number(10.68);
$x->dividedBy(2);          // 5.34

Modulo

modulo($num)

$num = number | string | Number()

Return new Number The value is the value of this Number modulos of $num

$x = new Number(10);
$x->modulo(3);          // 1

Equality and Comparison

Equals

equals($num)

$num = number | string | Number()

Return Boolean Return true if the value of Number is equal to $num, return false if not

$x = new Number(10);
$x->equals(10);         // true

Not equal

notEqual($num)

$num = number | string | Number()

Return Boolean Return true if the value of Number is not equal to $num, return false if not

$x = new Number(10);
$x->notEqual(10);       // false

Greater than

greaterThan($num)

$num = number | string | Number()

Return Boolean Return true if the value of Number is greater than to $num, return false if not

$x = new Number(10);
$x->greaterThan(10);     // false

Greater than or equal

greaterThanOrEqual($num)

$num = number | string | Number()

Return Boolean Return true if the value of Number is greater than or equal to $num, return false if not

$x = new Number(10);
$x->greaterThanOrEqual(10);      // true

Less than

lessThan($num)

$num = number | string | Number()

Return Boolean Return true if the value of Number is less than to $num, return false if not

$x = new Number(10);
$x->lessThan(11);               // true

Less than or equal

lessThanOrEqual($num)

$num = number | string | Number()

Return Boolean Return true if the value of Number is less than or equal to $num, return false if not

$x = new Number(10);
$x->lessThanOrEqual(9);         // false