polars.Config.set_float_precision#

classmethod Config.set_float_precision(precision: int | None = None) type[Config][source]#

Control the number of decimal places displayed for floating point values.

Parameters:
precisionint

Number of decimal places to display; set to None to revert to the default/standard behaviour.

Notes

When setting this to a larger value you should ensure that you are aware of both the limitations of floating point representations, and of the precision of the data that you are looking at.

This setting only applies to Float32 and Float64 dtypes; it does not cover Decimal dtype values (which are displayed at their native level of precision).

Examples

Set a large maximum float precision:

>>> from math import pi, e
>>> df = pl.DataFrame({"const": ["pi", "e"], "value": [pi, e]})
>>> with pl.Config(float_precision=15):
...     print(df)
shape: (2, 2)
┌───────┬───────────────────┐
│ const ┆ value             │
│ ---   ┆ ---               │
│ str   ┆ f64               │
╞═══════╪═══════════════════╡
│ pi    ┆ 3.141592653589793 │
│ e     ┆ 2.718281828459045 │
└───────┴───────────────────┘

Set a fixed float precision and align numeric columns to the right in order to cleanly line-up the decimal separator:

>>> df = pl.DataFrame(
...     {
...         "a": ["xx", "yy"],
...         "b": [-11111111, 44444444444],
...         "c": [100000.987654321, -23456789],
...     }
... )
>>> with pl.Config(
...     tbl_cell_numeric_alignment="RIGHT",
...     thousands_separator=",",
...     float_precision=3,
... ):
...     print(df)
shape: (2, 3)
┌─────┬────────────────┬─────────────────┐
│ a   ┆              b ┆               c │
│ --- ┆            --- ┆             --- │
│ str ┆            i64 ┆             f64 │
╞═════╪════════════════╪═════════════════╡
│ xx  ┆    -11,111,111 ┆     100,000.988 │
│ yy  ┆ 44,444,444,444 ┆ -23,456,789.000 │
└─────┴────────────────┴─────────────────┘