Description
The asType
function allows converting the result of a formula into a specified type, if possible. This function is useful for explicitly handling values as string
or number
.
Syntax
asType(type, expression)
Arguments
Argument | Description |
---|---|
type |
The desired type to convert the value into. Allowed values are: string , number . |
expression |
The input that should be converted to the specified type. |
Return Types
Returns the value of the expression as the specified type (string
or number
), if the conversion is successful.
Examples
Description | Formula | Result |
---|---|---|
Convert number to string | asType('string', 123) | "123" |
Convert string to number | asType('number', '456.78') | 456.78 |
Invalid conversion | asType('number', 'abc') | Error or null (depending on implementation) |
Notes
- The
asType
function should be used when explicit conversion is required, such as in dynamic formulas where the type is not clear. - If the conversion is not possible (e.g.,
asType('number', 'abc')
), an error may occur, ornull
may be returned. Always check input values before conversion. - For conversion to a number (
number
), a numerical or numerically formatted value is required. Decimal separators must be correctly specified (e.g.,.
instead of,
in English-based number formats). - This function is particularly useful when combined with other functions that require specific data types, such as
sumAll
orformat
.
Comments
0 comments
Please sign in to leave a comment.