Number Helpers
This page documents the number-specific handlebars helper expressions available in KX Dashboards templates.
Refer to Apply Templates for details on how to use these expressions.
addCommas
Adds commas to numbers.
Parameters:
num{Number}
Returns {String}
Example: {{addCommas "1234567"}} => 1,234,567
bytes
Formats a number to its equivalent in bytes, or a string as its length in bytes.
Examples:
Parameters:
argument{Number|String}
Returns {String}
phoneNumber
Converts a string or number to a formatted phone number.
Parameters:
num{Number|String}: The phone number to format, e.g.8005551212.
Returns {String}
Example: {{phoneNumber "8005551212"}} => (800) 555-1212
toAbbr
Returns the number in abbreviation formats based on a value. The number is rounded to a particular decimal place. This is for general numbers, not size in bytes.
Parameters:
number{Number}precision{Number}: An integer specifying the number of digits to appear after the decimal point (optional); default is 2.
Returns {String}
Example: {{toAbbr "1234567"}} => 1.23m
toExponential
Returns a string representing a number in exponential notation. One digit before the decimal point, rounded to fractionDigits after the decimal point.
Parameters:
number{Number}fractionDigits{Number}: Optional. An integer specifying the number of digits to appear after the decimal point. Defaults to as many digits as necessary to specify the number.
Returns {String}
Example: {{toExponential "5" 2}} => 5.00e+0
toFixed
Formats the given number using fixed-point notation.
Parameters:
number{Number}digits{Number}: Optional. The number of digits to appear after the decimal point; may be a value between 0 and 20. If omitted, treated as 0.
Returns {String}: A string representing the given number using fixed-point notation.
Example: {{toFixed "1.1234" 2}} => 1.12
toFloat
Parameters:
number{Number}
Returns {Number}
toInt
Parameters:
number{Number}
Returns {Number}
toPrecision
Returns a string representing number to the specified precision.
Parameters:
number{Number}precision{Number}: Optional. An integer specifying the number of significant digits. If precision is not between 1 and 100 (inclusive), it will be coerced to 0.
Returns {String}: A string representing number in fixed-point or exponential notation rounded to precision significant digits.
Example: {{toPrecision "1.1234" 2}} => 1.1