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.
integerFormat | |
---|---|
Formats the number value as an integer without decimal digits, if null prints an empty string. Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: INTEGER |
5.1234 → 5 null or "" → null |
integerFormatDefault | |
---|---|
Formats the number value as an integer without decimal digits, if null prints the default null value or "-". Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: STRING |
5.1234 → 5 null or "" → N/A |
singleDecimalFormat | |
---|---|
Formats the number value as a float with 1 decimal digit, if null prints an empty string. Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: FLOAT |
5.1234 → 5.1 null or "" → null |
singleDecimalFormatDefault | |
---|---|
Formats the number value as a float with 1 decimal digit, if null prints the default null value or "-". Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: STRING |
0.1234 → 0.1 null or "" → N/A |
twoDecimalFormat | |
---|---|
Formats the number value as a float with 2 decimal digits, if null prints an empty string. Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: FLOAT |
5.1234 → 5.12 null or "" → null |
twoDecimalFormatDefault | |
---|---|
Formats the number value as an integer with 2 decimal digits, if null prints the default null value or "-". Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: STRING |
0.1234 → 0.12 null or "" → N/A |
threeDecimalFormatDefault | |
---|---|
Formats the number value as an integer with 3 decimal digits, if null prints the default null value or "-". Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: STRING |
0.1234 → 0.123 null or "" → - |
singleDecimalFormatZero | |
---|---|
Formats the number value as a float with 1 decimal digit, if null prints 0. Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: FLOAT |
0.1234 → 0.1 null or "" → 0.0 |
twoDecimalFormatZero | |
---|---|
Formats the number value as an integer with 2 decimal digits, if null prints 0. Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: FLOAT |
0.1234 → 0.12 null or "" → 0.00 |
numberFormat | |
---|---|
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. Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: STRING |
10345 → 10,345 10.456 → 10,5 null or "" → null |
barToPSIWithUnit | |
---|---|
Formats the given float number converting from bar to psi adding the unit of measurement (psi). Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: STRING |
1 → 14.5038 psi null or "" → 0 psi |
barToPSI | |
---|---|
Formats the given float number converting from bar as PSI. Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: FLOAT |
1 → 14.5038 null or "" → 0 |
bytesToKBytes | |
---|---|
Formats the given number converting from bytes to Kbytes. Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: FLOAT |
1024 → 1 null or "" → 0 |
bytesToMBytes | |
---|---|
Formats the given number converting from bytes to Mbytes. Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: FLOAT |
1048576 → 1 null or "" → 0 |
celsiusToFahrenheitWithUnit | |
---|---|
Formats the given float number converting from celsius to Fahrenheit adding the unit of measurement (F). Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: STRING |
25 → 77 F null or "" → 0 F |
celsiusToFahrenheit | |
---|---|
Formats the given float number converting from celsius to Fahrenheit. Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: FLOAT |
25.0 → 77.0 null or "" → 0 |
floatToPercentageWithUnit | |
---|---|
Formats the given float number (0 to 1) as a percentage (0 to 100) with % sign. Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: STRING |
0.45 → 45 % null or "" → 0 % |
floatToPercentage | |
---|---|
Formats the given float number (0 to 1) as a percentage (0 to 100). Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: FLOAT |
0.45 → 45 null or "" → 0 |
literToGallonWithUnit | |
---|---|
Formats the given float number converting from liters to Gallons adding the unit of measurement (gal). Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: STRING |
1 → 0.264172 gal null or "" → 0 gal |
literToGallon | |
---|---|
Formats the given float number converting from liters to Gallons. Supported Input Types: INTEGER | FLOAT | NUMBER Output Type: FLOAT |
1 → 0.264172 null or "" → 0 |
Configuration Options
New variants can be defined through the following configuration options.
Option | Description | Sample Value |
---|---|---|
conversionFormula | The optional formula which can be used to convert values. | 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 |
nullValue | The null value to print if the input value is null or empty. | - |
precision | The number of decimal places to print. If not specified, no truncation is done. | 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 |
Example of defining a custom number filter variant:
exports.kilosToTons = NumberFormatter({ "precision": 1, "nullValue": 0, "conversionFormula": "value / 1000" });
Comments
0 comments
Please sign in to leave a comment.