pyspark.sql.functions.format_number#
- pyspark.sql.functions.format_number(col, d)[source]#
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.
New in version 1.5.0.
Changed in version 3.4.0: Supports Spark Connect.
- Parameters
- col
Column
or column name the column name of the numeric value to be formatted
- dint
the N decimal places
- col
- Returns
Column
the column of formatted results.
Examples
>>> import pyspark.sql.functions as sf >>> df = spark.createDataFrame([(5,)], ["a"]) >>> df.select("*", sf.format_number("a", 4), sf.format_number(df.a, 6)).show() +---+-------------------+-------------------+ | a|format_number(a, 4)|format_number(a, 6)| +---+-------------------+-------------------+ | 5| 5.0000| 5.000000| +---+-------------------+-------------------+