DecimalMark
Which character an amount's text uses as the decimal point: the dot or the comma.
'1.234' is a fraction just over one to an American and one thousand two hundred
and thirty-four to most of Europe. Nothing in the text itself can settle it — so the
money readers ask you, with a DecimalMark parameter. Whichever character you name
as the decimal point, the other one becomes the digit-grouping character (the
thousands separator) and is checked as such: a value written in the wrong notation
is rejected, never silently misread as a different number.
Members
| Member | Meaning |
|---|---|
Dot |
The dot is the decimal point; commas group digits: '1,234.56'. The US and invariant habit. This is the default. |
Comma |
The comma is the decimal point; dots group digits: '1.234,56'. Most of Europe. |
The enum is backed by an int — Dot is 0, Comma 1 — so a choice can be stored and
read back with DecimalMark::from().
Where it is used
Every method on CkMoney that reads an amount takes a mark
parameter — Amount, AmountOrNull, ToMoney, Format, MinorUnits, Round, Split,
the validators and the calculations alike — and Display takes into as well, the mark of
the text it writes. The default for every one of them is the dot
(CkSettings::DefaultDecimalMark).
Quick look
use SafeCoder\CommonKit\CkMoney;
use SafeCoder\CommonKit\Enums\DecimalMark;
CkMoney::Amount('1,234.56'); // -> 1234.56 (the dot is the default)
CkMoney::Amount('1.234,56'); // -> 0.0 (wrong notation: rejected, never misread)
CkMoney::Amount(
input: '1.234,56',
mark: DecimalMark::Comma
); // -> 1234.56
CkMoney::Display(
input: 1234.5,
currency: 'EUR',
into: DecimalMark::Comma
); // -> '1.234,50 EUR' (written the European way)