beginner4 min read

Number Fields

How number fields work for pricing, ratings, counts, and ordering, plus validation best practices.

What is a number field?

A number field stores numeric values — integers or decimals. It provides a numeric input in the CMS editor and enables mathematical operations like sorting, filtering, and calculations.

Common uses

Pricing

Store product prices, event ticket costs, or service rates as numbers. This enables:

  • Sorting by price (low to high, high to low).
  • Filtering by price range.
  • Displaying formatted currency.

Ratings

1-5 star ratings on testimonials, reviews, or products. Number fields let you:

  • Calculate average ratings.
  • Sort by rating.
  • Display star visualizations.

Counts and metrics

Quantitative data like:

  • Square footage (real estate).
  • Number of bedrooms/bathrooms.
  • Beneficiaries served (nonprofits).
  • Employee count (companies).
  • Read time in minutes (blog posts).

Display order

Manual sort order for collections where alphabetical or date order is not appropriate:

  • Team members (CEO first, then C-suite, etc.).
  • Services (primary offerings first).
  • Portfolio projects (best work first).

Inventory

Stock counts for products. Combined with conditional visibility, you can show "Out of stock" when the count is zero.

Number vs. text for numeric data

Always use a number field for data that is actually numeric. Storing prices as text ("$49.99") prevents sorting and filtering.

DataField TypeWhy
PriceNumberSort, filter, calculate
PhonePhone/TextNot used mathematically
YearNumberSort, filter
ZIP codeTextLeading zeros, not math
RatingNumberAverage, sort

Validation

Set appropriate constraints:

  • Min value — prevent negative prices (min: 0).
  • Max value — cap ratings at 5 (max: 5).
  • Integer only — for counts and order fields.
  • Decimal places — for prices (2 decimal places).

Formatting

Number fields store raw values. Formatting (currency symbols, commas, percentages) happens in your front-end display:

  • Store: 49.99 → Display: "$49.99"
  • Store: 1500 → Display: "1,500 sq ft"
  • Store: 0.85 → Display: "85%"

Tips

  1. Use number for prices, always — not text. Even if you need a dollar sign, store the raw number and format on display.
  2. Order fields default to 0 — set a default of 0 or 1 so new items sort predictably.
  3. Validate ranges — a rating above 5 or a negative price indicates bad data. Set min/max constraints.
  4. Do not store formatted strings — "1,500" and "$50" are text, not numbers. Store the raw numeric value.
  5. Consider null vs. zero — an empty number field (null) means "not set". Zero means "explicitly zero". These are different and should be handled differently in display logic.
fieldnumberpricingratingsordering

Ready to build?

Ready to build your CMS?

Trellis architects content structures that scale. Start for free — no credit card required.

Start for free