Skip to main content

NumberField

Formats a number for the active locale, with optional currency, unit and prefix/postfix.

Use it for anything numeric. A value that is semantically a code (order number, SKU) belongs in TextField — it should not get thousands separators.

Example​

<NumberField source="price" numberFormat={{style: 'currency', currency: 'CZK'}} />

<NumberField source="stock" postfix="pcs" />

Props​

On top of these the component accepts the shared field props.

NameTypeDefaultDescription
source (required)string—Name of the field on the record
localesstringadmin localeLocale used for toLocaleString
numberFormatIntl.NumberFormatOptionssee belowstyle ('currency' / 'unit'), currency, unit, minimumFractionDigits, maximumFractionDigits
prefixstringcurrency symbol when it leadsMuted text before the value
postfixstringcurrency/unit symbol when it trailsMuted text after the value
transform(value: unknown) => anynumeric strings → numbersMaps the raw value before formatting
emptyTextstring—Text shown when the value is empty

The currency or unit symbol is placed on the side the locale puts it on; an explicit prefix/postfix replaces it.

Schema options​

The schema layer maps the field's options onto the props above and supplies the fraction-digit defaults before rendering this component directly.

Schema keyPropDefault
options.numbernumberFormat{minimumFractionDigits: 2, maximumFractionDigits: 5}, or 0/0 for type: "integer"
options.prefixprefix—
options.postfixpostfix—
caution

The schema key is options.number, not options.numberFormat — numberFormat is the prop name on the component. A flat options.numberFormat in a backend schema is silently ignored.

tip

In a list, integer and decimal fields are right-aligned by default. Set options.textAlign to override it. A plain number field is not realigned — set options.textAlign: "right" explicitly if you want it to match.

Schema mapping​

type: "integer", type: "number", and type: "string" with format: "decimal":

{"name": "price", "type": "string", "format": "decimal",
"options": {"number": {"style": "currency", "currency": "CZK"}}}

The admin serializer fields fill options.number from the model field, so a DecimalField needs no extra configuration — AdminDecimalField copies its decimal_places into both fraction-digit bounds. habarico.models.MoneyField additionally carries the currency into the schema:

from django.db import models
from habarico.models import MoneyField


class Product(models.Model):
price = MoneyField(currency="CZK")
stock = models.PositiveIntegerField()

See also​