Skip to contents

Local version of scales::comma scales::percent

Usage

comma_cl(
  x,
  accuracy = NULL,
  scale = 1,
  prefix = "",
  suffix = "",
  big.mark = ".",
  decimal.mark = ",",
  trim = TRUE,
  digits,
  ...
)

percent_cl(
  x,
  accuracy = NULL,
  scale = 100,
  prefix = "",
  suffix = "%",
  big.mark = ".",
  decimal.mark = ",",
  trim = TRUE,
  ...
)

dollar_cl(
  x,
  accuracy = NULL,
  scale = 1,
  prefix = "$",
  suffix = "",
  big.mark = ".",
  decimal.mark = ",",
  trim = TRUE,
  largest_with_cents = 1e+05,
  negative_parens = FALSE,
  ...
)

Arguments

x

A numeric vector to format.

accuracy

NULL

scale

1

prefix

""

suffix

""

big.mark

"."

decimal.mark

","

trim

TRUE

digits

digits

...

Other arguments passed on to base::format().

largest_with_cents

largest_with_cents

negative_parens

negative_parens

Examples


x <- 10^c(1:10)

comma_cl(x)
#>  [1] "10"             "100"            "1.000"          "10.000"        
#>  [5] "100.000"        "1.000.000"      "10.000.000"     "100.000.000"   
#>  [9] "1.000.000.000"  "10.000.000.000"

comma_cl(x + .123, accuracy = 0.001)
#>  [1] "10,123"             "100,123"            "1.000,123"         
#>  [4] "10.000,123"         "100.000,123"        "1.000.000,123"     
#>  [7] "10.000.000,123"     "100.000.000,123"    "1.000.000.000,123" 
#> [10] "10.000.000.000,123"

comma_cl(x + .123, accuracy = 0.001, big.mark = " ")
#>  [1] "10,123"             "100,123"            "1 000,123"         
#>  [4] "10 000,123"         "100 000,123"        "1 000 000,123"     
#>  [7] "10 000 000,123"     "100 000 000,123"    "1 000 000 000,123" 
#> [10] "10 000 000 000,123"

scales::comma(x)
#>  [1] "10"             "100"            "1,000"          "10,000"        
#>  [5] "100,000"        "1,000,000"      "10,000,000"     "100,000,000"   
#>  [9] "1,000,000,000"  "10,000,000,000"

y <- runif(10)

percent_cl(y)
#>  [1] "38,47%" "0,17%"  "38,92%" "71,57%" "53,95%" "73,47%" "5,66%"  "70,95%"
#>  [9] "4,34%"  "35,06%"

dollar_cl(x)
#> Warning: The `negative_parens` argument of `dollar()` is deprecated as of scales 1.2.0.
#> Please use the `style_negative` argument instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
#>  [1] "$10"             "$100"            "$1.000"          "$10.000"        
#>  [5] "$100.000"        "$1.000.000"      "$10.000.000"     "$100.000.000"   
#>  [9] "$1.000.000.000"  "$10.000.000.000"

dollar_cl(x + .123, accuracy = 0.001)
#>  [1] "$10"             "$100"            "$1.000"          "$10.000"        
#>  [5] "$100.000"        "$1.000.000"      "$10.000.000"     "$100.000.000"   
#>  [9] "$1.000.000.000"  "$10.000.000.000"

dollar_cl(x + .123, accuracy = 0.0001, largest_with_cents = Inf)
#>  [1] "$10,12"             "$100,12"            "$1.000,12"         
#>  [4] "$10.000,12"         "$100.000,12"        "$1.000.000,12"     
#>  [7] "$10.000.000,12"     "$100.000.000,12"    "$1.000.000.000,12" 
#> [10] "$10.000.000.000,12"