Let’s use the exibble dataset to create a gt table. With fmt_number(), we’ll format the num column to have three decimal places (with decimals = 3) and omit the use of digit separators (with use_seps = FALSE).
Use a modified version of the countrypops dataset to create a gt table with row labels. Format all columns to use large-number suffixing (e.g., where "10,000,000" becomes "10M") with the suffixing = TRUE option.
In a variation of the previous table, we can combine large-number suffixing with a declaration of the number of significant digits to use. With things like population figures, n_sigfig = 3 is a very good option.
There can be cases where you want to show numbers to a large number of decimal places but also drop the unnecessary trailing zeros for low-precision values. Let’s take a portion of the towny dataset and format the latitude and longitude columns with fmt_number(). We’ll have up to 5 digits displayed as decimal values, but we’ll also unconditionally drop any runs of trailing zeros in the decimal part with drop_trailing_zeros = TRUE.
Another strategy for dealing with precision of decimals is to have a separate column of values that specify how many decimal digits to retain. Such a column can be added via cols_add() or it can be part of the input table for gt(). With that column available, it can be referenced in the decimals argument with from_column(). This approach yields a display of coordinate values that reflects the measurement precision of each value.