Let’s say you have a spell that retrieves a number as a string from an API response, but you need to perform mathematical operations on this value. You can use the To Float node to convert the string to a float before using it in your calculations.
Copy
1. API Request URL: https://example.com/data2. Get 'price' from response Input: API Request output Property: price3. To Float a: Get 'price' output4. Multiply a: To Float output b: 1.15. Format Number number: Multiply output decimals: 2
In this example, the ‘price’ value from the API response is extracted as a string using the Get node. The To Float node then converts this string value to a floating-point number. The converted value is multiplied by 1.1 and finally formatted with 2 decimal places for display.
Passing a non-numeric string to the To Float node will result in a NaN output. Make sure to validate or sanitize input data if necessary.
Floating-point arithmetic can sometimes produce unexpected results due to precision limitations. If you need exact decimal calculations, consider using a decimal library or rounding results as needed.