money
final class money implements JsonSerializable, Stringable
| internal |
Value Object: Money.
Stores currency amounts as integers (minor units) to avoid floating point errors. Example: R$ 10,00 is stored as 1000.
Capabilities:
- Immutable arithmetic (add, subtract, multiply).
- Automatic formatting based on Locale.
- Automatic currency resolution based on Locale.
- Dynamic decimal precision handling (JPY vs BRL vs KWD).
Constants
| DEFAULT_CURRENCY |
|
Properties
| string | $currency |
Methods
No description
String representation using formatted output.
Factory: Create from current user's Moodle Locale.
Create instance from a float value (Major Units).
Returns the amount as a float (Major Units).
Check if money represents zero.
Check if money is positive.
Check if money is negative.
Format the money for display using PHP's Intl NumberFormatter.
JSON Serialization.
Details
at line 51
__construct(int $amount, string $currency = '')
No description
at line 72
string
__toString()
String representation using formatted output.
at line 87
static money
from_current_locale(float $amount_float)
Factory: Create from current user's Moodle Locale.
If the user is viewing the site in "Português - Brasil" (pt_br), this creates a BRL money object.
at line 110
static money
from_float(float $amount, string $currency)
Create instance from a float value (Major Units).
Automatically calculates the minor units based on the currency precision.
Example: from_float(10.50, 'BRL') -> amount: 1050 Example: from_float(100, 'JPY') -> amount: 100
at line 127
float
to_float()
Returns the amount as a float (Major Units).
Useful for API responses or generic math.
at line 179
money
multiply(float $multiplier)
Multiply by a factor (e.g. tax calculation).
Rounds to the nearest integer unit.
at line 187
bool
is_zero()
Check if money represents zero.
at line 195
bool
is_positive()
Check if money is positive.
at line 203
bool
is_negative()
Check if money is negative.
at line 219
string
format(string|null $locale = null)
Format the money for display using PHP's Intl NumberFormatter.
at line 247
array
jsonSerialize()
JSON Serialization.