docs/utilities/format
Sections
Components
Utilities
Forms
Hooks
Copy Markdown
Format numbers, bytes, and time with Intl API.
PreviewCode
File size120 kB
CLIManual
pnpmbunnpmyarn
pnpm dlx shadcn@latest add @shark/format
import {
FormatByte,
FormatNumber,
FormatRelativeTime
} from "@/registry/react/components/format";
<FormatByte value={120_000} />
<FormatNumber value={1234567} />
<FormatRelativeTime value={new Date("2025-05-05")} />
Format byte values as file sizes.
PreviewCode
File size120 kB
Use the unitDisplay prop to control how the unit is displayed.
PreviewCode
Long: 1.5 megabytes
Short: 1.5 MB
Narrow: 1.5MB
Use unitSystem to choose between decimal (1000 bytes) or binary (1024 bytes).
PreviewCode
Decimal (1000): 1.02 kB
Binary (1024): 1 kB
Format dates as relative time.
PreviewCode
Last updated1 year ago
Use the style prop for long, short, or narrow format.
PreviewCode
Long: 1 year ago
Short: 1 yr. ago
Narrow: 1y ago
Format numbers with locale-aware options.
PreviewCode
Downloads1,234,567per month
Use style="currency" with the currency prop for currency formatting.
PreviewCode
USD: $99.99
EUR: €99.99
BRL: R$99.99
Use style="percent" to format numbers as percentages.
PreviewCode
Default: 75%
With decimals: 75.67%
Use notation="compact" for compact display.
PreviewCode
1.2M: 1.2M
120K: 120K
Downloads: 1.2M per month
| Prop | Type | Default |
|---|---|---|
value | number | - |
unit | "byte" | "bit" |
unitDisplay | "long" | "short" |
unitSystem | "decimal" | "binary" |
locale | string | - |
| Prop | Type | Default |
|---|---|---|
value | Date | number |
numeric | "always" | "auto" |
style | "long" | "short" |
locale | string | - |
| Prop | Type | Default |
|---|---|---|
value | number | - |
locale | string | - |
style | "decimal" | "percent" |
currency | string | - |
unit | string | - |
notation | "standard" | "compact" |
minimumFractionDigits | number | - |
maximumFractionDigits | number | - |
For a complete list of props, see the Ark UI documentation.
[
Previous page
Download Trigger ](/docs/utilities/download-trigger)[
Next page
Highlight ](/docs/utilities/highlight)
On This Page
InstallationUsageExamplesFormat ByteUnit displayUnit systemFormat Relative TimeStyleFormat NumberCurrencyPercentageCompact notationAPI ReferenceFormatByteFormatRelativeTimeFormatNumber