Transform and displays numeric values in different ways and formats.
This filter and its variants can be applied to metrics and properties of numeric type, or strings holding a numeric value.
Depending on the variant options, the underlying value is parsed as number and then formatted.
Filter Variants
The set of predefined filter variants that can be used to format values.
Bytes | |
Bytes to KBytes (##.#) | Formats the given number converting from bytes to Kbytes. Name: bytesToKBytes Input Types: INTEGER, FLOAT, NUMBER Output Type: FLOAT
|
Bytes to MBytes (##.#) | Formats the given number converting from bytes to Mbytes. Name: bytesToMBytes Input Types: INTEGER, FLOAT, NUMBER Output Type: FLOAT
|
Number | |
### | Formats the number value as an integer without decimal digits, if null prints an empty string. Name: integerFormat Input Types: INTEGER, FLOAT, NUMBER Output Type: INTEGER
|
### or N/A | Formats the number value as an integer without decimal digits, if null prints the default null value or "-". Name: integerFormatDefault Input Types: INTEGER, FLOAT, NUMBER Output Type: STRING
|
###.# | Formats the number value as a float with 1 decimal digit, if null prints an empty string. Name: singleDecimalFormat Input Types: INTEGER, FLOAT, NUMBER Output Type: FLOAT
|
###.# or N/A | Formats the number value as a float with 1 decimal digit, if null prints the default null value or "-". Name: singleDecimalFormatDefault Input Types: INTEGER, FLOAT, NUMBER Output Type: STRING
|
###.## | Formats the number value as a float with 2 decimal digits, if null prints an empty string. Name: twoDecimalFormat Input Types: INTEGER, FLOAT, NUMBER Output Type: FLOAT
|
###.## or N/A | Formats the number value as an integer with 2 decimal digits, if null prints the default null value or "-". Name: twoDecimalFormatDefault Input Types: INTEGER, FLOAT, NUMBER Output Type: STRING
|
###.### | Formats the number value as an integer with 3 decimal digits, if null prints the default null value or "-". Name: threeDecimalFormatDefault Input Types: INTEGER, FLOAT, NUMBER Output Type: STRING
|
##0.0 or 0.0 | Formats the number value as a float with 1 decimal digit, if null prints 0. Name: singleDecimalFormatZero Input Types: INTEGER, FLOAT, NUMBER Output Type: FLOAT
|
##0.00 | Formats the number value as an integer with 2 decimal digits, if null prints 0. Name: twoDecimalFormatZero Input Types: INTEGER, FLOAT, NUMBER Output Type: FLOAT
|
#,###.### | Formats a number in the localized format using decimal and thousand separators. The number of decimal places depends on the value: 0 decimal places if greater than 1000, 1 decimal place if greater than 100, 2 decimal places if greater than 10, 3 decimal places if less than 10. Name: numberFormat Input Types: INTEGER, FLOAT, NUMBER Output Type: STRING
|
Percentage | |
Float to Percentage (## %) | Formats the given float number (0 to 1) as a percentage (0 to 100) with % sign. Name: floatToPercentageWithUnit Input Types: INTEGER, FLOAT, NUMBER Output Type: STRING
|
Float to Percentage (##) | Formats the given float number (0 to 1) as a percentage (0 to 100). Name: floatToPercentage Input Types: INTEGER, FLOAT, NUMBER Output Type: FLOAT
|
Pressure | |
Bar to psi (##.# psi) | Formats the given float number converting from bar to psi adding the unit of measurement (psi). Name: barToPSIWithUnit Input Types: INTEGER, FLOAT, NUMBER Output Type: STRING
|
Bar to psi (##.#) | Formats the given float number converting from bar as PSI. Name: barToPSI Input Types: INTEGER, FLOAT, NUMBER Output Type: FLOAT
|
Temperature | |
Celsius to Fahrenheit (##.# F) | Formats the given float number converting from celsius to Fahrenheit adding the unit of measurement (F). Name: celsiusToFahrenheitWithUnit Input Types: INTEGER, FLOAT, NUMBER Output Type: STRING
|
Celsius to Fahrenheit (##.#) | Formats the given float number converting from celsius to Fahrenheit. Name: celsiusToFahrenheit Input Types: INTEGER, FLOAT, NUMBER Output Type: FLOAT
|
Volume | |
Liters to Gallons (##.# gal) | Formats the given float number converting from liters to Gallons adding the unit of measurement (gal). Name: literToGallonWithUnit Input Types: INTEGER, FLOAT, NUMBER Output Type: STRING
|
Liters to Gallons (##.#) | Formats the given float number converting from liters to Gallons. Name: literToGallon Input Types: INTEGER, FLOAT, NUMBER Output Type: FLOAT
|
Custom Variants
New variants can be defined through the following configuration options.
Option | Description | Sample Value |
---|---|---|
conversionFormula | The formula which can be used to convert values (optional). | value * 9/5 + 32 |
defaultNullValue | The flag that indicates whether to use the default null value in case the input value is null or empty. | true |
localize | If true, the number is formatted according to the page locale (default false). | |
nullValue | The null value to print if the input value is null or empty. | - |
minPrecision | The minimum number of decimal places to print (default 0). | 1 |
precision | The number of decimal places to print. | 2 |
scale | The multiplier applied to the input value before it is printed. (default 1) | 100 |
unit | The optional unit of measurement to display aside the value. (default null) | Kg |
useGrouping | If true and localize=true, the number is formatted by using the thousand separator (default false). | true |
Example of defining a custom number filter variants into the Custom Filters component.
exports.euros= NumberFormatter({ "precision": 2, "nullValue": "-", "localize": true, "useGrouping": true, "unit" : "€" });
exports.kilosToTons = NumberFormatter({ "precision": 1, "nullValue": 0, "conversionFormula": "value / 1000" });