# formatNanoseconds

Industry: Core

## Signature

```ts
formatNanoseconds(nanoseconds: bigint): string
```

Format nanoseconds since the Unix epoch as a decimal string, for JSON and other text transports.

- `JSON.stringify` throws a `TypeError` on a `bigint`, so a nanosecond timestamp cannot go into a JSON payload as-is. This is the bridge every consumer needs; do not hand-roll it.
- The output is a canonical decimal integer: an optional `-`, then digits, no leading zeros, no exponent, no separators. `parseNanoseconds` is its exact inverse.
- **Put the result in JSON as a string, not a number.** It is itself only the value — `{ observedAt: formatNanoseconds(n) }` serialises to `{"observedAt":"1710072000123456789"}`. Emitted unquoted it is a JSON number, and `JSON.parse` rounds it back through a double to `1710072000123456800` — the exact loss this namespace exists to prevent.
- Rejects values outside the range `Temporal.Instant` can represent (±8_640_000_000_000_000_000_000n), so anything formatted here can be read back and rendered.
- Returns "" on invalid input.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `nanoseconds` | `bigint` | nanoseconds since the Unix epoch (bigint) |

## Returns

decimal string form of the value, or "" on invalid input

## Examples

```ts
import { formatNanoseconds } from "@northguild/gmt/precision/format";

formatNanoseconds(1710072000123456789n) // "1710072000123456789"
```

## Source

[precision/format/formatNanoseconds.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/precision/format/formatNanoseconds.ts)
