Expand my Community achievements bar.

SOLVED

Converting String to Number in Fusion

Avatar

Level 6

This is a repeat question I'd asked - unanswered - in a subgroup on this site, so apologies if I'm over-posting... (edited to add PDF to illustrate the current observed behavior).

Is there a way to convert/coerce a variable data type to be a number instead of a string - particularly in the Set Variable module? I'm using the Set Variable module to initially set a var to zero; it treats it like a string. So after I set it, under certain conditions, I take the current variable value and have it add +1 to itself in a subsequent module. And I'm noticing that the subsequent module that adds 1 to the variable looks at the 0 as a string and sets the new value to "01". If I test-feed it a 3, it sets the value to "31".

If I feed it a 3, I would instead want it to compute and set the variable to 4. I'm not picky about whether it's an integer or float as long as I can do math with it.

How do I let Fusion know I want this to be a number and not a string? I am using the "+" operator from the math functions, and yet it's still treating the two values as strings.

Thanks!

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 4

Hi Mylah,

Thanks for all the details and screenshots. To accomplish this, simply use the parseNumber() function on the first module when you set the value to zero (e.g. parseNumber(0)) will, in fact, result in a number rather than a text string.

The default of the "Set Variable" module is string...so when setting a number like this...this parseNumber function will do the trick (you wouldn't need to do this if the number was an output from an API or something else).

View solution in original post

2 Replies

Avatar

Correct answer by
Level 4

Hi Mylah,

Thanks for all the details and screenshots. To accomplish this, simply use the parseNumber() function on the first module when you set the value to zero (e.g. parseNumber(0)) will, in fact, result in a number rather than a text string.

The default of the "Set Variable" module is string...so when setting a number like this...this parseNumber function will do the trick (you wouldn't need to do this if the number was an output from an API or something else).

Avatar

Level 6

@Darin Patterson - inactive‚ Excellent! Thank you;

"parseNumber(0;,)" is what worked. :)

I'd considered using parseNumber or formatNumber, then promptly forgot to try those functions.