# Convert Text to Number to use in formulas

Is it possible to convert Text option from a drop down into a number to use in a formula?

For eg. User selects 'Weekly, 'Monthly' or 'Yearly' from dropdown. I would then like to convert 'Weekly' into 1, 'Monthly' into 4 and Yearly into 52.18 to use in a formula.

Hi @latetotheparty
Try this:

{weeks= 1 if window=="Weekly" else (4 if window=="Monthly" else 52.18)}
total cost is {=weeks*20}

3 Likes

Dan beat me to it by a minute my example is formatted slightly differently but accomplishes the exact same thing:

{if: frequency=="Weekly"; trim=yes}{frequencynumber=1}{elseif: frequency=="Monthly"}{frequencynumber=4}{elseif: frequency=="Yearly"}{frequencynumber=52.18}{endif: trim=left}

Example of the value used in a formula: {=frequencynumber*5}

3 Likes

Thank you so much for your solutions! I was determined to solve it and came up with a different solution. Please correct me if I'm wrong.

Also, I had no idea I could create conditional variables. Thank you for that!

{formmenu: default=weekly; monthly; yearly; name=frequency; multiple=no}
Weekly cost:{=5*replace(replace(replace(frequency,"yearly",52.18),"monthly",4),"weekly",1)}

3 Likes

Wow, so many cool solutions. I like to drop my own version of the solution here.

{data=[
["name": "Weekly", "value": 1],
["name": "Monthly", "value": 4],
["name": "Yearly", "value": 52.18]
Weekly cost: {=5*frequency["value"]}

4 Likes

Should I say I'm late to the party Either way, here's Vinod's solution, in a slightly concise version:

{costs=[
"Weekly":1,
"Monthly": 4,
"Yearly": 52.18
]}
Using keyed lists with the `keys` function.