I have a need to convert a number in a variable to text which I will concat with another string and store in a different string variable. I’ve had a dig through the Expressions documentation but I can’t find a way to transform the numeric value to string.
Can anyone help?
EDIT: Never mind. I realized I can accomplish what I need simply by setting the value of the string variable manually and appending the number variable. Duh.
You could also do this with the replace() function in an expression as it attempts some implicit conversions.
myNumber = 2
replace("The value is {x} now!", "{x}", myNumber)
You could also use the stringify() method which JSON stringifies the input. In the case of a number, the output is the raw string value for the number.
myNumber = 2
concat("The value is ", stringify(myNumber), " now!")
Thanks Josh. I’ll take a look at those options. I just noticed my approach mentioned in my EDIT above is flawed anyway. If the number ends in a 0 it is dropped once added to the string.
Perhaps Josh. For context, if it’s not obvious, my number is a dollars and cents value.
I will give this a go. I really appreciate the guidance. I’m reasonably technical but never been a developer and some coding logic and syntaxes are difficult for me without good directions.
We added a new toFixed() method that will do this for you:
toFixed(input, digits) - takes a numeric input along with a number of digits to display and formats the number as a string with the specified number of digits (rounding if necessary)
input: numeric input value
digits: fixed number of digits after the decimal place to display (0-100)