Field Manual PHP / Laravel reference
← Financial-system patterns

Monetary values

Integer minor units avoid common binary floating-point representation errors.

What it is

Integer minor units avoid common binary floating-point representation errors.

When to use it

Store an amount together with its currency and defined scale.

Syntax

$amountInCents = 1250; // USD 12.50
// Avoid careless financial arithmetic with $amount = 12.50;

Example

$amountInCents = 1250;
$feeInCents = 25;
$totalInCents = $amountInCents + $feeInCents;
$currency = "USD";
// Parse decimal input as strings with an explicit scale and rounding rule.

Common mistakes

Currencies do not all have two decimals; multiplying an input float by 100 can still round incorrectly; guard overflow.

Related topics

Browse Financial-system patterns