NumberInput
Numbers and amounts in the format of the current locale, e.g. 1.234,56
in German and 1,234.56 in English. The saved value is exact (no floating
point).
use Anvil\Schema\Fields\NumberInput;
NumberInput::make('amount')->currency('EUR')->min(0),NumberInput::make('quantity')->integer()->min(1)->max(100)->default(1),NumberInput::make('probability')->integer()->min(0)->max(100)->suffix('%'),NumberInput::make('weight')->decimals(3)->suffix('kg'),Options
Section titled “Options”| Option | Effect | Default |
|---|---|---|
decimals(n) |
decimal places, 0 to 10 (otherwise InvalidArgumentException) |
0 |
integer() |
same as decimals(0) |
|
currency('EUR', 2) |
an amount: ISO 4217 code (three capital letters), decimals; the currency symbol is the suffix and the read-only value is formatted as money | none |
min(n), max(n) |
lower / upper limit (inclusive) | none |
prefix('…'), suffix('…') |
text before / after the input | none |
Plus the options of every field.
The input accepts the locale format with grouping (1.234,56) or without
(1234,56). The value is shown again in the locale format with the
configured decimals (1.234,50). More decimals than configured fail the
validation; they are never rounded silently.
Saved value
Section titled “Saved value”- with decimals: a normalised decimal string,
"1234.56"– use aDECIMAL(…)column, - without decimals: an
int, - empty:
null.
Validation
Section titled “Validation”localized_number[decimals], then localized_min[n] and
localized_max[n] when set (inclusive), then the rules of rules().
Spaces, also narrow and non-breaking ones, are accepted as grouping, and
− as minus sign.
Read-only
Section titled “Read-only”Locale formatted with prefix and suffix, e.g. 1.234,50 € for
currency('EUR') or 75 %.
Columns of tables format numbers the same way:
TextColumn::make('amount')->money('EUR'),
TextColumn::make('quantity')->numeric(2).
- without decimals: an
integerwithminimum/maximum, - with decimals: a string with a point and exactly the configured decimals
(
"1250.50"), so that no precision is lost. Requests may send a JSON number or a decimal string with a point; grouping or more decimals than the field has fail the validation.