Skip to main content

isNumber

Tests if Studio can parse the input value as a number. Returns a Boolean true or false.

The function returns true for numbers (e.g. 500) and valid numeric strings (e.g. '500'). By default, it returns true for currency strings (e.g. '$500'), but you can prevent this by using the function's optional parameter.

Generally, the function returns false for input strings that represent an abbreviated number (e.g. '1M' or '$5Bn'), but there are two known exceptions. See isNumber and abbreviations for details.

This function is typically used in conditional statements — see here for an example.

Parameters

  • INPUT (any)

    The value to check.

  • ACCEPT CURRENCY (Boolean)

    Optional. Whether to recognize currency strings as numbers. If set to false, the function does not recognize strings that include a currency symbol or currency ISO code (e.g. '$112' or 'AUD 123').

    Default: true

Examples

The function returns true when you input a number.

ATL in Script

Result

[[isNumber(12)]]

true

[[isNumber(1234.5678)]]

true

[[isNumber(-1234.5678)]]

true

Testing numeric strings

The function returns true in these scenarios:

ATL in Script

Result

Notes

[[isNumber('12')]]

true

The string represents a positive number.

[[isNumber('-12')]]

true

The string represents a negative number.

[[isNumber('1234.5678')]]

true

The string represents a positive number.

[[isNumber('-1234.5678')]]

true

The string represents a negative number.

[[isNumber('(500)')]]

true

The function parses '(500)' as -500.

The function returns false in these scenarios:

ATL in Script

Result

Notes

[[isNumber('twenty-two')]]

false

A string of alphabetic characters is not a number.

[[isNumber('')]]

false

An empty string is not a number.

Testing currency strings

By default, the function recognizes a valid currency string as a number.

A valid currency string is one in which a currency symbol or ISO code appears at the string's start or end.

ATL in Script

Result

Notes

[[isNumber('$500')]]

true

A currency symbol appears before the number.

[[isNumber('500$')]]

true

A currency symbol appears after the number.

[[isNumber('EUR500')]]

true

A currency code appears before the number.

[[isNumber('500EUR')]]

true

A currency code appears after the number.

[[isNumber('$ 500')]]

true

There can be a gap between the symbol and number.

[[isNumber('500 EUR')]]

true

There can be a gap between the code and number.

[[isNumber('EUR(500)')]]

true

The function parses 'EUR(500)' as -500.

[[isNumber('two cents')]]

false

A string of alphabetic characters is not a number.

[[isNumber('5 dollars')]]

false

The string does not contain a valid currency code/symbol.

[[isNumber('Ω500')]]

false

The omega symbol (Ω) is not a valid currency symbol.

[[isNumber('ZMV500')]]

false

ZMV is not a valid currency code.

You can change the default behavior by setting the ACCEPT CURRENCY parameter to false.

ATL in Script

Result

Notes

[[isNumber('$500', false)]]

false

A valid currency string is not recognized.

[[isNumber('EUR500', false)]]

false

A valid currency string is not recognized.

isNumber and abbreviations

Numeric/currency strings in your data should not include an abbreviation suffix.

ATL in Script

Result

Notes

[[isNumber('10M')]]

false

The function does not recognize '10M' as 10 million.

[[isNumber('20MM')]]

false

The function does not recognize '20MM' as 20 million.

[[isNumber('30Bn')]]

false

The function does not recognize '30Bn' as 300 billion.

The function returns false for most strings of this type, but there are two exceptions.

ATL in Script

Result

Notes

[[isNumber('100K')]]

true

'K' is the Myanmar kyat's currency symbol.

[[isNumber('200B')]]

true

'B' is the Panamanian balboa's currency symbol.

A recognized currency symbol can be at the end of a currency string. This is why the function parses '100K' as 100 kyats. It does not parse '100K' as the number 100,000. To avoid this, set ACCEPT CURRENCY to false.

Tip

This issue also affects asNumber. For example, the ATL [[asNumber('100K')]] returns 100 instead of 100,000. Best practice is to have no abbreviated-number strings in your data.

Using isNumber 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": "919575.4", "target": 2000000},
        {"branch": "Denver", "sales": "no value", "target": 1750000}
    ]
}

The "data" array contains four JSON objects. The sales values for the first two objects are numbers, the sales value for the third object is a numeric string, and the sales value for the fourth object is a non-numeric string.

You might write this user-defined function (UDF) script to generate a summary for each object:

#define getSummary(object)
	
[[object.branch]] achieved sales of [[abbreviateNumber(currencyFormat(object.sales))]].

This is a UDF script, so you need to call the function in another script. For example:

[[forAll(WholeJSON.data, object -> getSummary(object))]]

This tells Studio to run all objects in the "data" array through the getSummary script. The request returns an error because the getSummary script requires a number (or a string value that can be parsed to a number) from the input object's sales key. Remember, the fourth object's sales value is a non-numeric string.

The fix is to use isNumber in a conditional statement inside the getSummary script.

#define getSummary(object)

[[isNumber(object.sales) ? "[[object.branch]] achieved sales of [[abbreviateNumber(currencyFormat(object.sales))]]." : "The sales value for [[object.branch]] is unknown."]]

Now, [[forAll(WholeJSON.data, object -> getSummary(object))]] generates a summary for each object.

Austin achieved sales of $1.3M.

Boston achieved sales of $1.8M.

Dallas achieved sales of $919.6K.

The sales value for Denver is unknown.

Tip

The conditional statement is written in ternary syntax. See Syntax for conditionals.