- Formats
Formats
A Format defines how a quantity value is displayed to users. Formats control precision, unit labels, composite units (like feet-inches), and various display traits. Understanding format specifications is essential for creating consistent and user-friendly quantity displays.
FormatProps
FormatProps is the core interface that defines all format properties. Each property is documented with its constraints and valid values in the API reference. For additional context on format specifications, see the EC documentation on Format.
Format Types
Decimal Format
Displays values with a fixed number of decimal places.
Fractional Format
Displays values as fractions with specified denominator.
Scientific Format
Displays values in scientific notation (e.g., 1.23E+04).
Station Format
Specialized format for civil engineering station values. See Station Format Properties below.
Composite Formats
Format definitions that utilize composite units allow quantity values to be displayed across multiple units. Typical examples:
- Imperial length:
5'-3 1/2"(feet and inches) - Angles:
45°30'15"(degrees, minutes, seconds) - Surveying:
1+055.50(stations)
Composite format properties:
- includeZero - Whether to show zero values for sub-units
- spacer - String separator between sub-unit values
- units - Array of unit definitions with labels
Example: Feet-Inches Format
Station Format Properties
Station formatting in iTwin.js supports properties that control how values are broken down into major and minor station components:
stationOffsetSize
The stationOffsetSize property specifies the number of decimal places for calculating the station offset magnitude. This must be a positive integer greater than 0. This works with stationBaseFactor to determine the effective station offset using the formula: effective offset = stationBaseFactor * 10^stationOffsetSize.
stationBaseFactor
The stationBaseFactor property provides additional flexibility for station formatting by acting as a multiplier for the base offset calculation. This allows for non-standard station intervals that aren't simple powers of 10. The default value is 1.
Note: The
stationBaseFactorproperty is currently implemented as an iTwin.js-specific extension and is not supported in the native EC (Entity Context) layer. This feature will eventually be incorporated into the ECFormat specification to provide broader compatibility across the iTwin ecosystem.
Station Format Examples
| stationOffsetSize | stationBaseFactor | Value | Effective Offset | Formatted |
|---|---|---|---|---|
| 2 | 1 | 1055.5 | 100 | 10+55.50 |
| 3 | 1 | 1055.5 | 1000 | 1+055.50 |
| 2 | 5 | 1055.5 | 500 | 2+55.50 |
In the examples above:
- With
stationOffsetSize=2andstationBaseFactor=1: effective offset = 1 × 10² = 100 - With
stationOffsetSize=3andstationBaseFactor=1: effective offset = 1 × 10³ = 1000 - With
stationOffsetSize=2andstationBaseFactor=5: effective offset = 5 × 10² = 500
Format Traits
Format traits are flags that control various display behaviors:
- keepSingleZero - Always show at least one trailing zero
- showUnitLabel - Display the unit label after the value
- trailZeroes - Show trailing zeros up to specified precision
- use1000Separator - Insert thousand separators (e.g., commas)
- applyRounding - Apply rounding rules to precision
- fractionDash - Use dash in fractions (e.g., 3-1/2 instead of 3 1/2)
- keepDecimalPoint - Always show decimal point even for whole numbers
- zeroEmpty - Display zero values as empty string
Code Examples
Numeric Format Example
This example uses a simple numeric format with 4 decimal place precision:
Example Code
Composite Format Example
This example formats a metric value (meters) as feet-inches with fractional precision:
Example Code
See Also
- Units - Understanding unit definitions referenced in formats
- Format Sets - Persisting formats at application level
- Providers - Accessing and managing format definitions
- Parsing and Formatting - Applying formats to quantity values
Last Updated: 23 January, 2026