Download the PHP package penangites/number without Composer

On this page you can find all versions of the php package penangites/number. 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 number

Number

Latest Version on Packagist Tests Total Downloads

An immutable, chainable Number value object for PHP with exact bcmath arithmetic — plus a Percentage companion. No runtime dependencies beyond bcmath, no floating-point arithmetic, no drift.

After construction, addition, subtraction, multiplication and percentage operations are exact at any precision. Only divide() and round() discard digits — and they take an explicit scale and rounding mode, so precision is never lost silently.

For Laravel integration (Eloquent casts, validation), see penangites/laravel-number.

Installation

Requires PHP 8.3+ and the bcmath extension.

Usage

Creating numbers

Use strings for decimal values when every supplied digit must be preserved.

A float is stored as the shortest decimal that reads back as the same double, so nothing is invented and nothing is dropped — but a float has already lost whatever it lost before the call, and that shows:

Scientific notation is accepted wherever a decimal string is — Percentage included — because it is what a float cast, a JSON decode or a database driver hands back. It is expanded positionally, so '1.0E-5' and '0.00001' are the same value. Exponents beyond ±100000 are refused: a value needing more digits than that should be written out in full, where the input is as large as the result.

Reading values

toInt() only converts losslessly: it throws on fractional values instead of silently truncating.

Arithmetic

Every operation returns a new instance — a Number never changes. Operands can be another Number, an int, a string, or a float.

Division and rounding

Division is the one operation that can produce endless digits, so it takes an explicit scale (default 12) and a RoundingMode (default half away from zero):

Modes: HalfAwayFromZero (default), Up, Down, Ceiling, Floor. Rounding uses the exact remainder, so every mode is correct even when the discarded digits lie far beyond the scale.

Values are returned in canonical form without trailing zeros. The scale limits decimal precision; it does not format or pad the result:

Percentages

A Percentage has no string cast: "0.06" and "6" are both plausible, so ask for toPercent(), toRatio() or toArray() by name rather than have the wrong one render silently.

Percentage supports exact add, subtract, negate, comparisons and sign checks of its own:

Apply one to a Number:

increaseBy / decreaseBy are the general-purpose names for tax / discount. All percentage operations are exact — chain ->round() when you need to limit decimal precision.

A complete price calculation can stay exact until the final rounding step:

Comparison

Recipes

Spelling a number out in words

Deliberately not part of this package — PHP's intl extension already does it in every CLDR locale, so use it directly:

Testing

This runs code style checks (Pint), static analysis (PHPStan at level 10, the maximum) and the Pest test suite.

Changelog

See CHANGELOG for what has changed recently.

Contributing

See CONTRIBUTING for details.

Security

If you discover a security issue, please read our security policy — do not use the issue tracker.

License

MIT — see LICENSE.


All versions of number with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
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 penangites/number contains the following files

Loading the files please wait ...