Use this file to discover all available pages before exploring further.
The Money class is the primary class for working with monetary values in Laravel Brick Money. It wraps the Brick\Money\Money class and provides a fluent Laravel interface.
Returns Money of the given amount and currency.By default, the money is created with a DefaultContext. This means that the amount is scaled to match the currency’s default fraction digits. For example, Money::of('2.5', 'USD') will yield USD 2.50. If the amount cannot be safely converted to this scale, an exception is thrown.To override this behaviour, a Context instance can be provided. Operations on this Money return a Money with the same context.
public static function of( BigNumber|float|int|string $amount, Currency|string $currency, ?Context $context = null, RoundingMode $roundingMode = RoundingMode::UNNECESSARY): static
Returns Money from a number of minor units (cents).By default, the money is created with a DefaultContext. This means that the amount is scaled to match the currency’s default fraction digits. For example, Money::ofMinor('1234', 'USD') will yield USD 12.34. If the amount cannot be safely converted to this scale, an exception is thrown.
public static function ofMinor( BigNumber|float|int|string $amount, Currency|string $currency, ?Context $context = null, RoundingMode $roundingMode = RoundingMode::UNNECESSARY): static
Returns the amount of this Money in minor units (cents) for the currency.The value is returned as a BigDecimal. If this Money has a scale greater than that of the currency, the result will have a non-zero scale.For example, USD 1.23 will return a BigDecimal of 123, while USD 1.2345 will return 123.45.
Returns the sum of this Money and the given amount.If the operand is a Money, it must have the same context as this Money, or an exception is thrown. This is by design, to ensure that contexts are not mixed accidentally.The resulting Money has the same context as this Money. If the result needs rounding to fit this context, a rounding mode can be provided. If a rounding mode is not provided and rounding is necessary, an exception is thrown.
public function plus( Money|BigNumber|float|int|string $that, RoundingMode $roundingMode = RoundingMode::UNNECESSARY): static
Returns the difference of this Money and the given amount.If the operand is a Money, it must have the same context as this Money, or an exception is thrown. This is by design, to ensure that contexts are not mixed accidentally.The resulting Money has the same context as this Money. If the result needs rounding to fit this context, a rounding mode can be provided. If a rounding mode is not provided and rounding is necessary, an exception is thrown.
public function minus( Money|BigNumber|float|int|string $that, RoundingMode $roundingMode = RoundingMode::UNNECESSARY): static
Returns the product of this Money and the given number.The resulting Money has the same context as this Money. If the result needs rounding to fit this context, a rounding mode can be provided. If a rounding mode is not provided and rounding is necessary, an exception is thrown.
public function multipliedBy( BigNumber|float|int|string $that, RoundingMode $roundingMode = RoundingMode::UNNECESSARY): static
Returns the result of the division of this Money by the given number.The resulting Money has the same context as this Money. If the result needs rounding to fit this context, a rounding mode can be provided. If a rounding mode is not provided and rounding is necessary, an exception is thrown.
public function dividedBy( BigNumber|float|int|string $that, RoundingMode $roundingMode = RoundingMode::UNNECESSARY): static
Returns the quotient of the division of this Money by the given number.The given number must be an integer value. The resulting Money has the same context as this Money. This method can serve as a basis for a money allocation algorithm.
public function quotient(BigNumber|int|float|string $that): Money
Returns the quotient and the remainder of the division of this Money by the given number.The given number must be an integer value. The resulting monies have the same context as this Money. This method can serve as a basis for a money allocation algorithm.
public function quotientAndRemainder(BigNumber|int|float|string $that): array
Allocates this Money according to a list of ratios.If the allocation yields a remainder, its amount is split over the first monies in the list, so that the total of the resulting monies is always equal to this Money.For example, given a USD 49.99 money in the default context, allocate(1, 2, 3, 4) returns [USD 5.00, USD 10.00, USD 15.00, USD 19.99]The resulting monies have the same context as this Money.
Allocates this Money according to a list of ratios.The remainder is also present, appended at the end of the list.For example, given a USD 49.99 money in the default context, allocateWithRemainder(1, 2, 3, 4) returns [USD 4.99, USD 9.98, USD 14.97, USD 19.96, USD 0.09]The resulting monies have the same context as this Money.
public function allocateWithRemainder(int ...$ratios): array
Splits this Money into a number of parts.If the division of this Money by the number of parts yields a remainder, its amount is split over the first monies in the list, so that the total of the resulting monies is always equal to this Money.For example, given a USD 100.00 money in the default context, split(3) returns [USD 33.34, USD 33.33, USD 33.33]The resulting monies have the same context as this Money.
Splits this Money into a number of parts and a remainder.For example, given a USD 100.00 money in the default context, splitWithRemainder(3) returns [USD 33.33, USD 33.33, USD 33.33, USD 0.01]The resulting monies have the same context as this Money.
public function splitWithRemainder(int $parts): array
Converts this Money to another currency, using an exchange rate.By default, the resulting Money has the same context as this Money. This can be overridden by providing a Context.For example, converting a default money of USD 1.23 to EUR with an exchange rate of 0.91 and RoundingMode::UP will yield EUR 1.12.
public function convertedTo( Currency|string $currency, BigNumber|float|int|string $exchangeRate, ?Context $context = null, RoundingMode $roundingMode = RoundingMode::UNNECESSARY): Money
Formats this Money.Note that this method uses number_format, which internally represents values using floating point arithmetic, so discrepancies can appear when formatting very large monetary values.
public function format(bool $allowWholeNumber = false): string
Formats this Money with the given locale.Note that this method uses NumberFormatter, which internally represents values using floating point arithmetic, so discrepancies can appear when formatting very large monetary values.
public function formatLocale( ?string $locale = null, bool $allowWholeNumber = false, ?Closure $callback = null): string