Download the PHP package andkom/php-decimal without Composer

On this page you can find all versions of the php package andkom/php-decimal. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-decimal

php-decimal

Arbitrary-precision decimal arithmetic library for PHP, built on top of the bcmath extension.

Provides both mutable (Decimal) and immutable (DecimalImmutable) implementations with a full set of arithmetic operations, rounding modes, comparisons, and formatting options.

Requirements

Installation

Quick Start

Creating Decimals

Method Description
new Decimal($value, $scale) Constructor, value is a string, scale is optional
Decimal::create($value, $scale) Factory, auto-detects type (string, int, float, Decimal)
Decimal::createFromString($value, $scale) From string, supports scientific notation (e.g. '1.5e-3')
Decimal::createFromFloat($value, $scale) From float, auto-detects scale if not provided
Decimal::createFromInteger($value, $scale) From integer
Decimal::createFromDecimal($decimal, $scale) Clone from another Decimal

Default Scale

Arithmetic

All arithmetic methods accept an optional $scale parameter to override the result scale.

Method Description
add($value, $scale) Addition
subtract($value, $scale) Subtraction
multiply($value, $scale) Multiplication
divide($value, $scale) Division
modulus($value) Modulo (remainder)
power($value, $scale) Exponentiation (supports negative exponents)
squareRoot($scale) Square root

Rounding

All rounding methods accept an optional $precision parameter. Positive precision rounds decimal places, negative precision rounds to powers of 10.

Method Description
round($precision, $mode) Round with specified mode (default: ROUND_HALF_UP)
roundUp($precision) Round away from zero
roundDown($precision) Round toward zero (truncation)
roundHalfUp($precision) Round half away from zero
roundHalfDown($precision) Round half toward zero
roundHalfEven($precision) Round half to even (banker's rounding)
roundHalfOdd($precision) Round half to odd
floor($precision) Round toward negative infinity
ceil($precision) Round toward positive infinity
truncate($precision) Truncate toward zero

Rounding Mode Constants

Constant Value
ROUND_UP 1
ROUND_DOWN 2
ROUND_HALF_UP 3
ROUND_HALF_DOWN 4
ROUND_HALF_EVEN 5
ROUND_HALF_ODD 6

Sign Operations

Method Description
inverse() Flip sign (positive becomes negative and vice versa)
negate() Always return negative value
absolutize() Always return positive value (absolute value)

Conversion & Formatting

Method Description
toFloat() Convert to PHP float
toInt() Convert to PHP int (truncates decimal part)
toString($trailingZeros) String without trailing zeros (default), or with
toFixed($precision) String with exact decimal places (does not mutate)
toFormat($precision, $decPoint, $thousandsSep, $trailingZeros, $mode) Formatted number with thousands separator
toScientific($precision, $exponent) Scientific notation (e.g. '1.23E4')
toDigits($digits) Round to N significant digits
toDecimal() Clone as new instance of same type
toMutable() Convert to mutable Decimal
toImmutable() Convert to immutable DecimalImmutable

Comparisons

All comparison methods accept an optional $scale parameter.

Method Description
compareTo($arg, $scale) Returns -1, 0, or 1
isEqual($arg, $scale) Equal to
isNotEqual($arg, $scale) Not equal to
isGreaterThan($arg, $scale) Greater than
isGreaterThanOrEquals($arg, $scale) Greater than or equal
isLessThan($arg, $scale) Less than
isLessThanOrEquals($arg, $scale) Less than or equal

Predicates

Method Description
isInteger() True if no fractional part
isDecimal() True if has fractional part
isPositive() True if greater than zero
isNegative() True if less than zero
isZero() True if equal to zero
isNotZero() True if not equal to zero
isEven() True if integer part is even
isOdd() True if integer part is odd

Static Helpers

Method Description
Decimal::max(...$args) Returns the maximum value
Decimal::min(...$args) Returns the minimum value

Mutable vs Immutable

Decimal is mutable -- operations modify the instance in place and return $this:

DecimalImmutable always returns a new instance, leaving the original unchanged:

Convert between them with toMutable() and toImmutable().

Running Tests


All versions of php-decimal with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-bcmath Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package andkom/php-decimal contains the following files

Loading the files please wait ...