Download the PHP package aichadigital/lara100 without Composer
On this page you can find all versions of the php package aichadigital/lara100. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aichadigital/lara100
More information about aichadigital/lara100
Files in aichadigital/lara100
Package lara100
Short Description Laravel cast for handling decimal values as base-100 integers (cents/centesimals)
License MIT
Homepage https://github.com/aichadigital/lara100
Informations about the package lara100
Lara100 — Exact Decimal for Laravel
Development happens on gitlab.castris.com. The GitHub repository is a read-only distribution mirror: issues and pull requests opened there are not seen.
A Laravel package providing an immutable, scale-configurable exact decimal value object (FixedDecimal) and a matching Eloquent cast (FixedDecimalCast). Values are stored as plain integers (unscaled) in the database; the cast and value object handle all precision arithmetic using brick/math under the hood.
Why Lara100?
Floating-point arithmetic is not safe for monetary or fiscal values:
FixedDecimal eliminates this class of error entirely:
Arithmetic is exact at every step. The result serialises as a decimal string ('0.3'), not a float, so API consumers and hash-based fiscal systems (AEAT Verifactu, etc.) always receive the canonical value.
Requirements
- PHP 8.3 or 8.4
- Laravel 12.x or 13.x
brick/math^0.14.2 (pulled in automatically)
Installation
No configuration file is required — lara100 ships with no publishable config.
Usage
1. Database schema
Store unscaled integers. The scale is declared at the model level, not in the column:
2. Model casts
Declare the cast with the scale as a colon-separated suffix. The scale is required; omitting it throws immediately rather than silently misinterpreting the column:
3. Reading and writing
The cast accepts only FixedDecimal|null on assignment. Scalars are rejected deliberately — callers must choose the conversion explicitly:
Assigning a raw scalar throws InvalidFixedDecimal — the strict contract prevents accidental precision loss at the boundary:
4. Constructing FixedDecimal
Recommended constructors:
Migration-only boundary (not for new code):
5. Arithmetic
All arithmetic produces a new FixedDecimal; the original is unchanged (immutable):
Available arithmetic: plus, minus, multipliedBy, dividedBy, toScale, negated, abs.
6. Comparison
7. Output
8. RoundingMode
lara100 ships its own RoundingMode enum — fully encapsulated from the underlying brick/math engine:
| Case | Description | Typical use |
|---|---|---|
HalfUp |
0.5 rounds away from zero | EU/Spain fiscal standard; default |
HalfEven |
0.5 rounds to nearest even | Banker's rounding; accounting |
HalfDown |
0.5 rounds toward zero | Conservative rounding |
Up |
Always away from zero | Always round up |
Down |
Always toward zero (truncate) | Always truncate |
Ceiling |
Toward positive infinity | |
Floor |
Toward negative infinity |
HalfUp is the European/Spanish fiscal standard and the default wherever lara100 accepts a rounding mode. HalfEven (banker's rounding) is the right choice for general accounting aggregations.
Positioning
lara100 is a Laravel-native, scale-aware exact decimal built on top of brick/math. It occupies a specific niche — here is when to reach for each option:
| Library | Abstraction | Laravel cast | Currency | When to use |
|---|---|---|---|---|
| lara100 | FixedDecimal (exact, scale-aware) |
Yes (FixedDecimalCast) |
No | Prices, rates, fiscal amounts in Laravel — exact arithmetic without currency overhead |
brick/math |
BigDecimal, BigInteger |
No | No | Raw exact arithmetic outside Laravel; lara100 builds on this |
brick/money |
Money (amount + currency) |
No | Yes | Multi-currency systems, allocation, currency conversion |
moneyphp/money |
Money (amount + currency) |
No | Yes | Same as brick/money; wider ecosystem adoption |
Choose lara100 when:
- You are building a Laravel application and want Eloquent models to carry
FixedDecimalattributes directly - You need exact arithmetic over scale-aware values (prices at scale 2, VAT rates at scale 4, etc.)
- You do not need multi-currency support or allocation algorithms
Reach for brick/math directly when:
- You need exact arithmetic outside of Laravel (CLI tools, pure PHP libraries, etc.)
- You need
BigIntegerorBigRational(lara100 only wrapsBigDecimal)
Reach for brick/money or moneyphp/money when:
- You need currency codes, currency conversion, or monetary allocation (splitting a total into N parts that sum exactly)
lara100 encapsulates brick/math ^0.14.2 internally. The dependency is lightweight; brick types are not exposed except via the explicit toBigDecimal() escape hatch.
Comparison with Alternatives
| Solution | DB column | PHP value | Precision | Laravel cast | Multi-currency |
|---|---|---|---|---|---|
lara100 FixedDecimal |
INTEGER (unscaled) |
FixedDecimal (exact) |
Exact | Yes | No |
lara100 Base100Int |
INTEGER (cents) |
int |
Exact | Yes | No |
brick/math (BigDecimal) |
— | BigDecimal (exact) |
Exact | No | No |
brick/money |
INTEGER |
Money (exact + currency) |
Exact | No | Yes |
moneyphp/money |
INTEGER |
Money (exact + currency) |
Exact | No | Yes |
Native DECIMAL column |
DECIMAL(10,2) |
float |
Float — imprecise | No | No |
Testing
Code Quality
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Security Vulnerabilities
If you discover a security vulnerability, please send an e-mail to Abdelkarim Mateos Sanchez via [email protected].
Credits
- Abdelkarim Mateos Sanchez
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
About AichaDigital
AichaDigital is an IT company focused on IT services.
All versions of lara100 with dependencies
brick/math Version ^0.14.2
illuminate/contracts Version ^12.0||^13.0
illuminate/database Version ^12.0||^13.0
spatie/laravel-package-tools Version ^1.16