Download the PHP package vrnedwidek/php-decimal without Composer
On this page you can find all versions of the php package vrnedwidek/php-decimal. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vrnedwidek/php-decimal
More information about vrnedwidek/php-decimal
Files in vrnedwidek/php-decimal
Package php-decimal
Short Description An arbitrary-precision Decimal class type for PHP. Forked from Piggly and updated requirements to allow PHP 8.1 and PHP 8.2.
License MIT
Homepage https://github.com/vrnedwidek/php-decimal
Informations about the package php-decimal
An arbitrary-precision Decimal class type for PHP
This library is similar to decimal.js, all business logic credits and copyrights go to Michael Mclaughlin and yours contributors.
The piggly/php-decimal
is fully compatible with PHP and so fast as decimal.js library. See below all features attached to it.
Features
This library is mainly composed by Decimal
class. A Decimal
is composed by coefficients, exponent and sign. It can handle integer and float values with an arbitrary-precision.
Here precision is specified in terms of significant digits rather than decimal places, and all calculations are rounded to the precision (similar to Python's decimal module) rather than just those involving division.
This library also adds the trigonometric functions, among others, and supports non-integer powers, which makes it a significantly larger library.
- Integers and floats;
- Simple but full-featured API;
- Replicates many of the native math methods;
- Also handles hexadecimal, binary and octal values;
- Faster and easier to use than another PHP libraries;
- No dependencies or requirements;
- Comprehensive documentation and test set.
Usage
Decimal
can handle integers, floats, strings and Decimal
objects:
A value can also be in binary, hexadecimal or octal if the appropriate prefix is included:
A Decimal
is immutable in the sense that it is not changed by its methods, always returning a new object
.
All methods which returns Decimal values can be chained.
Many method names have a shorter alias.
There are many ways to convert a Decimal
to an string,
and almost all methods are available as static
.
Decimal
can handle with INF
and NAN
values.
There are many methods to do any checks to Decimal
.
By the way, there is a toFraction
method with an optional maximum denominator argument.
All calculations are rounded according to the number of significant digits and rounding mode specified by the precision
and rounding
properties of the DecimalConfig
object.
Each Decimal
class is associated to a DecimalConfig
. It may be the global
configuration, or a custom configuration to that specific decimal number.
For advanced usage, multiple Decimal
can be created, each with their own independent configuration which applies to all Decimal
numbers created from it.
The value of a Decimal
object is stored in a floating point format in terms of its digits
, exponent
and sign
.
For further information see the decimal.js API since this library is fully compatible with it.
Installation
Composer
- At you console, in your project folder, type
composer require piggly/php-decimal
; - Don't forget to add Composer's autoload file at your code base
require_once('vendor/autoload.php);
.
Manual install
- Download or clone with repository with
git clone https://github.com/piggly-dev/php-decimal.git
; - After, goes to
cd /path/to/piggly/php-decimal
; - Install all Composer's dependencies with
composer install
; - Add project's autoload file at your code base
require_once('/path/to/piggly/php-decimal/vendor/autoload.php);
.
Dependencies
The library has the following external dependencies:
- PHP 7.3+.
TODO
In code, there annotations @todo
with some improvements that this library may need.
Changelog
See the CHANGELOG file for information about all code changes.
Testing the code
This library uses the PHPUnit. We carry out tests of all the main classes of this application.
You must always run tests with PHP 7.3 and greater. Any changes at this library need to pass of all oldest and newests tests.
!! Some tests are heavy, be careful while testing them, they may require huge memory available.
Contributions
See the CONTRIBUTING file for information before submitting your contribution.
Credits
- Caique Araujo;
- All contributors;
decimal.js
Support the project
Piggly Studio is an agency located in Rio de Janeiro, Brazil. If you like this library and want to support this job, be free to donate any value to BTC wallet 3DNssbspq7dURaVQH6yBoYwW3PhsNs8dnK
❤.
License
MIT License (MIT). See LICENSE.
All versions of php-decimal with dependencies
ext-bcmath Version ^7.3 || ^8