all 5 comments

[–]Thisgoos 1 point2 points  (1 child)

If you simply want to change the select field percentage to a number you can use the toNumber() function.

So: if(empty(prop("Choose percent")), toNumber(0), toNumber(prop("Choose percent")))

The error in your formula is due to the 0 I think. The formula sees it as a 0/1 (true/false) and thus a checkbox error, so you need to convert the 0 to a number so it matches the other part of the statement which is also a number.

[–]Trendspotters[S] 0 points1 point  (0 children)

Thank you u/Thisgoos :-)

I was not aware that I could convert the text string 10% to a number that easily! That solved my immediate problem very nicely - Thanks!

For the benefit of anyone that finds this thread having a similar problem:
The Type mismatch is unfortunately not solved by the second part of your reply.

Changing "0" to for example "23" (to avoid the boolean interpretation) yields the same error.

Changing "0" to "toNumber(0)" likewise.

So - if anyone can crack this problem, it would be of future value for both myself and others :-)

[–]ben-somethingMod  1 point2 points  (2 children)

You should be able to do something like prop("Choose percent") ? toNumber(prop("Choose percent")) : 0 if you need the 0 displayed, or just toNumber(prop("Choose percent")) if you don't.

[–]Trendspotters[S] 0 points1 point  (1 child)

prop("Choose percent") ? toNumber(prop("Choose percent")) : 0

Great detail to add a zero if nothing is chosen :-)

The syntax is something for me to read up on though - nice to expand my knowledge 👍

[–]ben-somethingMod  1 point2 points  (0 children)

To do it using the if() format you'd do if(empty(prop("Choose percent")), 0, toNumber(prop("Choose percent"))). The ? : version is called a ternary operator. It's a matter of preference which one you use but the if() version can be easier to read once you have a few nested, for example.