---
title: "formatFileSize"
description: "Format a byte count into a human-readable size string such as KB, MB, or GB, ideal for upload and download user interfaces."
canonical_url: "https://core.mhaibaraai.cn/en/docs/helpers/file/format-file-size"
---
# formatFileSize

> Format a byte count into a human-readable size string such as KB, MB, or GB, ideal for upload and download user interfaces.

## Usage

`formatFileSize` formats a byte count into a human-readable file size string.

```ts
import { formatFileSize } from '@movk/core'

console.log(formatFileSize(1024)) // '1 KB'
console.log(formatFileSize(1536)) // '1.5 KB'
console.log(formatFileSize(1048576)) // '1 MB'
console.log(formatFileSize(1073741824)) // '1 GB'

// Edge cases
console.log(formatFileSize(0)) // '0 Bytes'
console.log(formatFileSize(-100)) // '0 Bytes'
```

## API

### `formatFileSize(bytes)`

Format a file size.

### Parameters

**bytes** (`number`) *required*: The file size in bytes.

### Returns

**returns** (`string`): The formatted file size string.

## Changelog

See commit history for [src/helpers/file/formatFileSize.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/helpers/file/formatFileSize.ts).

---

- [GitHub](https://github.com/mhaibaraai/movk-core/blob/main/src/helpers/file/formatFileSize.ts)


## Sitemap

See the full [sitemap](https://core.mhaibaraai.cn/sitemap.md) for all pages.
