View source: R/style_helpers.R
number_format | R Documentation |
This function creates a number formatting expression that formats numeric values according to locale-specific conventions. It can be used in tooltips, popups, and text fields for symbol layers.
number_format(
column,
locale = "en-US",
style = "decimal",
currency = NULL,
unit = NULL,
minimum_fraction_digits = NULL,
maximum_fraction_digits = NULL,
minimum_integer_digits = NULL,
use_grouping = NULL,
notation = NULL,
compact_display = NULL
)
column |
The name of the column containing the numeric value to format. Can also be an expression that evaluates to a number. |
locale |
A string specifying the locale to use for formatting (e.g., "en-US", "de-DE", "fr-FR"). Defaults to "en-US". |
style |
The formatting style to use. Options include:
|
currency |
For style = "currency", the ISO 4217 currency code (e.g., "USD", "EUR", "GBP"). |
unit |
For style = "unit", the unit to use (e.g., "kilometer", "mile", "liter"). |
minimum_fraction_digits |
The minimum number of fraction digits to display. |
maximum_fraction_digits |
The maximum number of fraction digits to display. |
minimum_integer_digits |
The minimum number of integer digits to display. |
use_grouping |
Whether to use grouping separators (e.g., thousands separators). Defaults to TRUE. |
notation |
The formatting notation. Options include:
|
compact_display |
For notation = "compact", whether to use "short" (default) or "long" form. |
A list representing the number-format expression.
# Basic number formatting with thousands separators
number_format("population")
# Currency formatting
number_format("income", style = "currency", currency = "USD")
# Percentage with 1 decimal place
number_format("rate", style = "percent", maximum_fraction_digits = 1)
# Compact notation for large numbers
number_format("population", notation = "compact")
# Using within a tooltip
concat("Population: ", number_format("population", notation = "compact"))
# Using with get_column()
number_format(get_column("value"), style = "currency", currency = "EUR")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.