Skip to main content

Number Value Methods

Number fields should be assigned with finite numeric values. Convert external input with Number(...), then validate it with Number.isFinite(...).

Assignment​

const amount = Number(payload.input.amount);
if (!Number.isFinite(amount)) {
throw new Error('AMOUNT_INVALID');
}

await context.form.update({
recordId: 'record-id',
data: {
amount,
},
});

Accepted input examples:

InputNormalized Value
12001200
'1200.50'1200.5
''invalid unless the field is intentionally cleared

Common Methods​

MethodUse
Number(value)Convert string or unknown input to number
Number.isFinite(value)Validate that the result is a real number
Math.round(value)Round to the nearest integer
Math.floor(value) / Math.ceil(value)Round down or up
value.toFixed(digits)Format a number for display or external text payloads
Math.max(...) / Math.min(...)Clamp or compare values

Number(value)​

Convert string or unknown input to a number.

const amount = Number(payload.input.amount);

Number.isFinite(value)​

Validate the converted number before writing it.

const amount = Number(payload.input.amount);
if (!Number.isFinite(amount)) {
throw new Error('AMOUNT_INVALID');
}

Math.round(value)​

Round to the nearest integer.

const score = Math.round(Number(payload.input.score || 0));

Math.floor(value) / Math.ceil(value)​

Round down or up.

const requestedQuantity = Math.floor(Number(payload.input.quantity || 0));
const pageCount = Math.ceil(Number(payload.input.total || 0) / 20);

value.toFixed(digits)​

Format a number with fixed decimal places. Convert it back with Number(...) when the field needs a number.

const unitPrice = Number(payload.input.unitPrice || 0);
const displayPrice = unitPrice.toFixed(2);
const roundedPrice = Number(unitPrice.toFixed(2));

Math.max(...) / Math.min(...)​

Clamp a number into an allowed range.

const quantity = Math.max(0, Math.floor(Number(payload.input.quantity || 0)));
const discountRate = Math.min(100, Math.max(0, Number(payload.input.discountRate || 0)));