Skip to contents

Use locale_info() to set independent number, percent and date conventions. Digit grouping, separators, percent sign placement and decimal digit sets use offline Unicode CLDR 48.0.0 data. A Unicode u-nu extension requests a positional digit set. The bare "ar" chart profile retains its Arabic-Indic digits and unmarked punctuation. Regional Arabic tags use CLDR conventions.

Usage

forma_format(
  x,
  type = c("number", "percent", "date"),
  lang = NULL,
  digits = NULL,
  date_format = "date_medium",
  tz = "UTC",
  locale = NULL
)

Arguments

x

Numeric vector, or a Date/POSIXt vector for dates.

type

Either "number", "percent" or "date". Percent input is a proportion.

lang

Optional formatting tag such as "de-CH". Supply either lang or locale. The default is English.

digits

Decimal places from zero to 15. Numbers show up to two decimal places by default and percentages up to one. Explicit digits keep trailing zeros.

date_format

ICU date pattern or style for stringi::stri_datetime_format().

tz

Time zone for Date/POSIXt formatting.

locale

Configuration returned by locale_info().

Value

A character vector. Missing inputs remain missing.

Examples

forma_format(c(0.25, 0.875), "percent", "ar", digits = 1)
#> [1] "٢٥٫٠٪" "٨٧٫٥٪"
forma_format(as.Date("2026-11-26"), "date", "en-GB", date_format = "date_short")
#> [1] "26/11/2026"
fmt <- locale_info("zh", number_locale = "de-CH", percent_locale = "tr")
forma_format(c(1234.5, 2345), locale = fmt)
#> [1] "1'234.5" "2'345"