isTypeNumber
Tests if the data type of the input value is a number and returns a Boolean true or false.
The similar isNumber function tests if a value can be parsed to a number, meaning it returns true for numbers and valid number/currency strings (e.g. '$100'). By contrast, isTypeNumber
returns true if the data type of the input value is number.
The function may be used in conditionals — see below for an example.
Parameters
VALUE (any)
The value to test.
Examples
Assume a "Describe a JSON Object" project with this data:
{ "data": { "mnth": "January", "year": "2023", "state": "California", "branches": [ "Los Angeles", "San Francisco", "Oakland" ], "totalSales": 245687.89, "sales": [ 80678.50, 91000.39, 74000.00 ], "target": 250000, "manager": { "name": "Robyn Banks", "age": 51, "married": false } } }
Here's how you might use isTypeNumber
to check values in the data:
ATL in Text | Result | Notes |
---|---|---|
| false | The test value is a string. |
| false | The test value is a JSON array. |
| true | The test value is a number. |
| false | The test value is a JSON object. |
| true | The test value is a number. |
| false | The test value is a Boolean. |
Using isTypeNumber in a conditional statement
Assume a "Describe a JSON Object" project with this data:
{ "data": [ {"branch": "Austin", "sales": 1345929.12, "target": 1250000}, {"branch": "Boston", "sales": 1838534.77, "target": 1750000}, {"branch": "Dallas", "sales": "no value", "target": 2000000}, {"branch": "Denver", "sales": "no value", "target": 1750000} ] }
The "data" array contains four JSON objects, each containing three key–value pairs.
Suppose you want the average sales value for this dataset. The standard approach is to map the array to a list of sales values, then calculate the average by using mean. For example:
[[ allSalesValues = map(WholeJSON.data, object -> object.sales) mean(allSalesValues)]] ]]
This produces an error because the sales values for the third and fourth objects are non-numeric strings, which the mean
function cannot handle. The mean
function can handle nulls (by default, it ignores them), so here you could test if each sales value is a number and convert the non-numeric values to nulls. For example:
[[ allSalesValues = map(WholeJSON.data, object -> object.sales) convertedSalesList = map(allSalesValues, value -> isTypeNumber(value) ? value : null) avgSalesValue = mean(convertedSalesList) "The average sales value is [[abbreviateNumber(currencyFormat(avgSalesValue))]]." ]]
The map function converts the list to:
|
Now each value in the list is numeric or null, so you can calculate the average value.
The output text is:
The average sales value is $1.6M.