---
title: format_number
description: "format\\_number function in PySpark: Formats the number X to a format like '#,--#,--#.--', rounded to d decimal places with HALF\\_EVEN round mode, and returns the result as a string."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/functions/format_number
---

# format\_number

Formats the number X to a format like '#,--#,--#.--', rounded to d decimal places with HALF\_EVEN round mode, and returns the result as a string.

For the corresponding Databricks SQL function, see [`format_number` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/format_number.md).

## Syntax

```python
from pyspark.sql import functions as dbf

dbf.format_number(col=<col>, d=<d>)
```

## Parameters

| Parameter | Type                          | Description                                          |
| --------- | ----------------------------- | ---------------------------------------------------- |
| `col`     | `pyspark.sql.Column` or `str` | the column name of the numeric value to be formatted |
| `d`       | `int`                         | the N decimal places                                 |

## Returns

`pyspark.sql.Column`: the column of formatted results.

## Examples

```python
from pyspark.sql import functions as dbf
df = spark.createDataFrame([(5,)], ["a"])
df.select("*", dbf.format_number("a", 4), dbf.format_number(df.a, 6)).show()
```
