The sub_zero() function

Let’s generate a simple, single-column tibble that contains an assortment of values that could potentially undergo some substitution.

tbl <- dplyr::tibble(num = c(10^(-1:2), 0, 0, 10^(4:6)))

tbl
# A tibble: 9 × 1
        num
      <dbl>
1       0.1
2       1  
3      10  
4     100  
5       0  
6       0  
7   10000  
8  100000  
9 1000000  

With this table, the zero values in will be given replacement text with a single call of sub_zero().

tbl |>
  gt() |>
  fmt_number(columns = num) |>
  sub_zero()
num
0.10
1.00
10.00
100.00
nil
nil
10,000.00
100,000.00
1,000,000.00