#docs #tql

ValueFormatter

Specifies how query values are displayed in the UI.

Using a ValueFormatter, you can round values, specify a suffix, or format values as percentages.

Rounding

Here’s how to round values to the nearest integer:

"valueFormatter": {
  "options": {
    "maximumFractionDigits": 0,
  }
}

Currencies

Here’s how to format values as dollars, with two decimal places:

"valueFormatter": {
  "options": {
    "style": "currency",
    "currency": "USD",
    "minimumFractionDigits": 2,
  },
  "locale": "en-US"
}

Percentages

Here’s how to format values as percentages, with one decimal place:

"valueFormatter": {
  "options": {
    "style": "percent",
    "minimumFractionDigits": 1,
  }
}

Units

Here’s how to format values with a unit, e.g. “100,000 users”:

"valueFormatter": {
  "options": {
    "style": "unit",
    "unit": "user",
    "unitDisplay": "long",
  }
}

Locales

Locales are used to format values according to the locale of the user. For example, the locale en-US formats values as US dollars, while the locale en-GB formats values as British pounds. Leave the locale empty to use the default locale of the user’s browser.

Style Options

OptionDescription
styleSets the style of the value, “decimal” (default), “currency”, “percent”, or “unit”.
currencyThe currency to use in currency formatting. Possible values are the ISO 4217 currency codes, such as “USD” for the US dollar, “EUR” for the euro, or “CNY” for the Chinese RMB
currencyDisplayHow to display the currency in currency formatting. Options are “code”, “symbol”, “narrowSymbol”, and “name”.
currencySignIn many locales, accounting format means to wrap the number with parentheses instead of appending a minus sign. Possible values are “standard” and “accounting”; the default is “standard”.
unitThe unit to use in unit formatting. Possible values are here
unitDisplayHow to display the unit in unit formatting. Options are “short”, “narrow”, and “long”.

Digit Options

OptionDescription
minimumFractionDigitsSets the minimum number of digits after the decimal point.
minimumIntegerDigitsThe minimum number of integer digits to use. A value with a smaller number of integer digits than this number will be left-padded with zeros (to the specified length) when formatted. Possible values are from 1 to 21; the default is 1.
maximumFractionDigitsSets the maximum number of digits after the decimal point.
minimumSignificantDigitsThe minimum number of significant digits to use.
maximumSignificantDigitsThe maximum number of significant digits to use.
roundingPriorityThe rounding priority to use. Options are “morePrecision”, “lessPrecision”, and “auto”.
roundingIncrementIndicates the increment at which rounding should take place relative to the calculated rounding magnitude. Possible values are 1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, and 5000; the default is 1. It cannot be mixed with significant-digits rounding or any setting of roundingPriority other than auto.
roundingModeThe rounding mode to use. Options are “ceil”, “floor”, “expand”, “trunc”, “halfCeil”, “halfFloor”, “halfExpand”, “halfTrunc”, and “halfEven”.
trailingZeroDisplayWhether to display trailing zeros. Options are “auto”, “stripIfInteger”, and “stripIfNotInteger”

Other Options

OptionDescription
notationThe formatting that should be displayed for the number. Possible values are “standard”, “scientific”, “engineering”, and “compact”.
compactDisplayWhether to display compact notation. Options are “short”, and “long”, default is “short”.
useGroupingWhether to use grouping separators, such as thousands separators or thousand/lakh/crore separators. Options are “auto”, “always”, and “min2” to only use grouping for numbers with at least two digits.
signDisplayWhether to display the sign. Options are “auto”, “always”, “never”, “negative”, and “exceptZero”.