Documents v0.10.0 · previews run the real runtime · experimental features are marked exp

format()

functionsince 0.10experimentalrequires runtime

A number or a datetime as text, in the language of the nearest lang attribute.

On this page · 8 sections+

Syntax

format(<value>, "decimal" | "integer" | "percent" | "currency" | "<date pattern>" [, "<currency code>"])

registry syntax: format(value, "decimal" | "integer" | "percent" | "currency" | "date pattern" [, "currency code"])

Parameters

valuenumber, numeric string or datetimerequired
A number is never taken as a timestamp, and a datetime never as a number.
style or patternquoted text or keywordrequired
Checked when the stylesheet is compiled.
currencyISO 4217 codefor `"currency"`
Any other style or pattern takes no third argument.

Return value

A string.

Example

invoice.cssreactive
.invoice { --qty: state(1); }.invoice button:on(click) { --qty: increment(1); }.invoice .total { text: format(--qty * 19.9, "currency", "EUR"); }.invoice .rate { text: format(0.19, "percent"); }
state()Function · hover any red tokenMakes each matching element the owner of an independent state with an initial value.Reference →

Behavior

  • Numbers. "decimal": grouping, at most 3 decimals. "integer": rounds half away from zero, never -0. "percent": 0.42 is 42%. "currency": needs a code.
  • Dates. Pattern fields: yyyy yy M MM MMM MMMM d dd E EEE EEEE H HH h hh m mm s ss SSS a. 'quoted' text is literal; '' is one quote. Numeric fields use the Gregorian calendar and Latin digits in every locale; names are localized.
  • Language. The nearest lang attribute, read once per element; none or invalid: the browser's.
  • CSS. @font-face format("woff2") stays CSS: only calls with two or more arguments and an unquoted first one are claimed.

Supported contexts

  • :on() actions: set(lower(event(value))).
  • :when() and when() conditions: :when(includes(--a, --b)).
  • Declarations, including text:: text: length(trim(--value)).

Limitations

  • In a custom bundle without the datetime feature, a date pattern is reported by feature.
Experimental · syntax may change between minor versions