> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ploterr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Number formats

> Write a scale or a length as text.

`formatLength` writes a length in metres as dimension text. `formatScale` writes a drawing scale as a label such as `1:50`.

## Import

```typescript theme={null}
import { formatScale, formatLength, defaultLengthFormat } from '@opengeometry/floorkit';
```

## Example

```typescript theme={null}
import { formatLength } from '@opengeometry/floorkit';

console.log(formatLength(10.3, { system: 'metric' })); // 10300
console.log(
  formatLength(1.25, {
    system: 'metric',
    display: 'm',
    precision: 2,
    showUnit: true,
  }),
); // 1.25 m
console.log(formatLength(0.3048, { system: 'imperial' })); // 1'
```

```typescript theme={null}
import { formatScale } from '@opengeometry/floorkit';

console.log(formatScale(1 / 50)); // 1:50
console.log(formatScale(2)); // 2:1
console.log(formatScale(0)); // NTS
console.log(formatScale(1 / 48, 'imperial'));
```

## Notes

* The metric default is millimetres with no decimals. The imperial default is feet and inches, to 1/16 inch.
* A viewport at 1:50 has `scale: 1 / 50`.
* A scale that is zero, negative or not a number gives `NTS`.
* A length that is not a finite number gives an empty string.

## formatScale

The scale label for a sheet or a viewport.

```typescript theme={null}
function formatScale(ratio: number, system?: UnitSystem, scaleId?: string): string;
```

## formatLength

Format a model length for a dimension label.

```typescript theme={null}
function formatLength(meters: number, format: LengthFormat): string;
```

## defaultLengthFormat

The default format for a unit system — what a dimension gets when unstyled.

```typescript theme={null}
function defaultLengthFormat(
  system: UnitSystem,
): Required<Pick<LengthFormat, 'system' | 'display' | 'precision'>>;
```

## Types

### LengthFormat

```typescript theme={null}
interface LengthFormat {
  system: UnitSystem;
  display?: LengthDisplay;
  precision?: number;
  showUnit?: boolean;
  prefix?: string;
  suffix?: string;
}
```

<ResponseField name="system" type="UnitSystem" required />

<ResponseField name="display" type="LengthDisplay">
  Defaults to `mm` for metric and `ft-in` for imperial.
</ResponseField>

<ResponseField name="precision" type="number">
  Metric: decimal places. Imperial `ft-in`/`in`: the fraction denominator to round to (2, 4, 8, 16,
  32 or 64). Defaults to 0 metric, 16 imperial.
</ResponseField>

<ResponseField name="showUnit" type="boolean">
  Print the unit after the value ("3000 mm"). Imperial always marks its units.
</ResponseField>

<ResponseField name="prefix" type="string" />

<ResponseField name="suffix" type="string" />

### LengthDisplay

How a length is written.

```typescript theme={null}
type LengthDisplay = 'mm' | 'cm' | 'm' | 'ft-in' | 'in';
```

## Related

* [`UnitSystem`](/floorkit/api/annotations/dimension-geometry#unitsystem)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.