Download the PHP package jimeneztdavid/scaled-int-laravel without Composer
On this page you can find all versions of the php package jimeneztdavid/scaled-int-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jimeneztdavid/scaled-int-laravel
More information about jimeneztdavid/scaled-int-laravel
Files in jimeneztdavid/scaled-int-laravel
Package scaled-int-laravel
Short Description Laravel integration for jimeneztdavid/scaled-int.
License MIT
Informations about the package scaled-int-laravel
ScaledInt Laravel
Laravel integration for jimeneztdavid/scaled-int.
Why this package exists
ScaledInt solves a common problem in money and decimal-based attributes: databases store exact integers, while applications often need values such as 10.25, 2.750, or similar scaled numbers.
This package bridges that gap for Laravel. It lets you work with readable major values in your models while storing the minor integer representation in the database. That keeps arithmetic exact, avoids floating-point errors, and keeps Eloquent attributes simple to use.
The package also provides an Artisan command to add the cast to a model automatically.
Installation
Why this package exists in practice
Float math is not reliable for exact values
That is fine for approximate scientific calculations, but not for money, discounts, taxes, or any value that must round exactly.
Storing money as a float creates long-term problems
If you store a price as a float, you are asking the database and PHP to preserve decimal precision that binary floats do not represent cleanly.
Common Laravel workaround:
This works, but it means every model repeats the same logic. It also pushes rounding decisions into many places instead of one.
Comparisons with floats can be misleading
With scaled integers, the comparison is exact because the stored value is an integer.
The same problem appears when saving and loading values
Many projects end up doing this manually:
That means multiplying by 100 on write, dividing by 100 on read, and keeping the column as an integer. ScaledIntCast does that for you in one place.
What you get with ScaledInt
- exact integer-based math
- consistent rounding
- easier comparisons
- less custom accessor/mutator code
- clearer intent in your models and services
Usage
Model cast
What the cast does
- stores the minor integer in the database
- returns a
Jimeneztdavid\ScaledInt\ScaledIntinstance when reading the attribute - accepts
ScaledInt, major numeric strings, integer minor values, andnull
Example with data
ScaledInt methods
The jimeneztdavid/scaled-int package provides a value object with safe decimal arithmetic.
Creating values
Reading values
minor()returns the stored integer valuescale()returns the scale used by the valuetoMajorString()returns the human-readable decimal string- casting the object to string returns the same major value
Arithmetic
Comparisons
Accepted assignment values
Jimeneztdavid\ScaledInt\ScaledIntinstance, for exampleScaledInt::fromMajor('10.25')- major numeric strings, such as
'10.25', stored as1025 - integer minor values, such as
1025, returned as10.25 null, stored asnull
Supported usage patterns
Artisan command
Options:
--scale=100--force--dry-run
The command supports both existing casts(): array methods and legacy $casts properties.
Configuration
Configuration options:
default_scale: fallback scale used when no scale is passed toScaledIntCastdefault_cast: default cast class for package configuration
All versions of scaled-int-laravel with dependencies
illuminate/console Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
jimeneztdavid/scaled-int Version ^1.2