Skip to content

Round to a number of significant figures

Description

Round to a number of significant figures

Usage

<Expr>$round_sig_figs(digits)

Arguments

digits Number of significant figures to round to.

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(a = c(0.01234, 3.333, 1234))

df$with_columns(
  rounded = pl$col("a")$round_sig_figs(2)
)
#> shape: (3, 2)
#> ┌─────────┬─────────┐
#> │ a       ┆ rounded │
#> │ ---     ┆ ---     │
#> │ f64     ┆ f64     │
#> ╞═════════╪═════════╡
#> │ 0.01234 ┆ 0.012   │
#> │ 3.333   ┆ 3.3     │
#> │ 1234.0  ┆ 1200.0  │
#> └─────────┴─────────┘