Download the PHP package jimeneztdavid/scaled-int without Composer

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

ScaledInt

Why this package exists

Working with money, prices, weights, percentages, or any decimal-based value using floating-point numbers (float) is dangerous. Rounding errors, precision loss, and unexpected comparisons are common problems in real-world applications.

ScaledInt solves this by:

This makes it ideal for:


Core concept

A ScaledInt stores:

Example with scale 100:

Human value Stored minor
10.25 1025
5.00 500
-3.50 -350

Installation


Creating values

From a major (human) value

From a minor (integer) value

Using a custom scale

Scale must be a power of 10 (10, 100, 1000, ...)


Reading values

Get minor value

Get scale

Convert back to string


Comparisons

All comparisons require the same scale.

compareTo()

Use compareTo() when you want a single method that tells you the ordering between two ScaledInt values.

Both numbers must have the same scale, otherwise an InvalidArgumentException is thrown.

Example

min() and max()

Use min() to get the smaller value and max() to get the larger value.

Both values must have the same scale.

between()

Use between() to check whether a value is inside an inclusive range.

Both bounds and the value must have the same scale.


Arithmetic operations

Addition

Subtraction

Multiply by integer

Divide by integer (exact)

Throws if the division is not exact.


Division with rounding

Supported modes:


Percentages


Common scenarios

Calculate IVA (VAT)


Extract IVA from a final price

IVA included price formula:

Example with 19% IVA:


Discounts


Measurements (non-money)


Why not floats?


Design principles


When to use ScaledInt

Financial calculations
Taxes and percentages
Measurements
Precise comparisons

Scientific floating-point math
Values requiring arbitrary precision decimals


Float vs ScaledInt

Aspect float ScaledInt
Precision Imprecise (binary rounding errors) Exact (integer math)
Internal representation IEEE 754 binary floating point Integer + fixed scale
0.1 + 0.2 0.30000000000000004 "0.30"
Equality comparison Unreliable Safe and deterministic
Rounding control Implicit and inconsistent Explicit (UP, DOWN, HALF_UP, HALF_EVEN)
Overflow detection Silent Explicit exceptions
Currency safety Dangerous Designed for money
Percentage calculations Error-prone Deterministic
Comparisons (> < ==) Risky Guaranteed correctness
Domain intent Generic numeric Explicit domain modeling
Production suitability Needs extra care Safe by default

License

MIT


All versions of scaled-int with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3
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 jimeneztdavid/scaled-int contains the following files

Loading the files please wait ...