021/numeric

A PHP library for working with precise numbers.

v1.0.0 2024-04-08 09:25 UTC

This package is auto-updated.

Last update: 2024-10-08 10:25:36 UTC


README

A PHP library to convenient work with arbitrary precision numbers.

Tests Total Downloads Latest Stable Version License

Requirements

  • PHP 8.1 or higher

Library is based on Brick\Math package:

Although the library can work seamlessly on any PHP installation, it is highly recommended that you install the GMP or BCMath extension to speed up calculations. The fastest available calculator implementation will be automatically selected at runtime.

Installation

You can install the package via composer:

composer require 021/numeric

Usage

use function O21\Numeric\Helpers\num;

$number = num('123.456');

echo $number->add('0.544')->get();

Calculations

All computational functions accept as an argument a value of one of the following types: string, float, int, \O21\Numeric\Numeric, \Brick\Math\BigNumber.

Comparisons

All comparison functions accept as an argument a value of one of the following types: string, float, int, \O21\Numeric\Numeric, \Brick\Math\BigNumber.

Formatting

Helpers

Namespace: O21\Numeric\Helpers