Description
The asNumber function returns the value of the parameter as a number, rounding the value to two decimal places if possible.
Syntax
asNumber(number)
Arguments
| Argument | Description |
|---|---|
| number | A numeric value or a string representing a number. The function attempts to convert this value into a number. |
Return Type
asNumber returns a numeric representation of the input value, rounded to two decimal places if convertible.
Examples
| Example | Result |
|---|---|
| asNumber('3.14159265359') | 3.14 |
| asNumber(123.4567) | 123.46 |
| asNumber('abc') | Error (invalid input value) |
Notes
- The input can be a number or a string. If the string does not represent a valid number (e.g., "abc"), the function returns an error.
- The function rounds the output to two decimal places by default.
- For large numbers or strings that are not in the standard number format, the function may produce unexpected results. It is recommended to validate the input.
asNumberdoes not work with data in currency formats or numbers with special characters (e.g., "€", "$"). These characters must be removed before using the function.
Comments
0 comments
Please sign in to leave a comment.