Customize how a biginteger or bigfloat vector is displayed. The precision can be controlled with a number of significant figures, or with a maximum or fixed number of digits after the decimal point. You can also choose between decimal, scientific and hexadecimal notations.

The default formatting applied when printing depends on the type of object:

  • standalone vector: consults "bignum.sigfig" and "bignum.max_dec_width"

  • tibble column: consults "pillar.sigfig" and "pillar.max_dec_width"

# S3 method for bignum_biginteger
format(
  x,
  ...,
  sigfig = NULL,
  digits = NULL,
  notation = c("fit", "dec", "sci", "hex")
)

# S3 method for bignum_bigfloat
format(x, ..., sigfig = NULL, digits = NULL, notation = c("fit", "dec", "sci"))

Arguments

x

A biginteger or bigfloat vector.

...

These dots are for future extensions and must be empty.

sigfig

Number of significant figures to show. Must be positive. Cannot be combined with digits.

If both sigfig and digits are unspecified, then consults the "bignum.sigfig" option (default: 7).

digits

Number of digits to show after the decimal point. Positive values indicate the exact number of digits to show. Negative values indicate the maximum number of digits to show (terminal zeros are hidden if there are no subsequent non-zero digits). Cannot be combined with sigfig.

notation

How should the vector be displayed? Choices:

  • "fit": Use decimal notation if it fits, otherwise use scientific notation. Consults the "bignum.max_dec_width" option (default: 13).

  • "dec": Use decimal notation, regardless of width.

  • "sci": Use scientific notation.

  • "hex": Use hexadecimal notation (positive biginteger only).

Value

Character vector

Examples

# default uses decimal notation
format(bigfloat(1e12))
#> [1] "1000000000000"

# until it becomes too wide, then it uses scientific notation
format(bigfloat(1e13))
#> [1] "1e+13"

# hexadecimal notation is supported for positive integers
format(biginteger(255), notation = "hex")
#> [1] "0xff"

# significant figures
format(bigfloat(12.5), sigfig = 2)
#> [1] "13."

# fixed digits after decimal point
format(bigfloat(12.5), digits = 2)
#> [1] "12.50"

# maximum digits after decimal point
format(bigfloat(12.5), digits = -2)
#> [1] "12.5"