Adding Numbers inside formulas - how to add 2 page variables

Hi,

I wanted to share something that I spend a while trying to solve.

Imagine you have 2 input fields with underlying variables - variable1 and variable2. Both variables are of type number. After pressing a button, both variables should be added to a new variable “result”.

In the logic underlying the button you would use the following formula to be assigned “result”:

pageVars.variable1+pageVars.variable2

Formula editor shows you as expected that 1 + 1 will give you result of 2.

When you fire up the app and test it, you will get 11 instead. Somehow number variable is not treated as number variable. To fix this you need to do explicit type conversion like this:

NUMBER(pageVars.variable1)+NUMBER(pageVars.variable2)

Above formula will give you correct result of 2.

I believe this should be a bug @Harri_Sarsa ? or is it similar to https://tracker.appgyver.com/bug-reports/p/incorrect-textinput-binding-to-number-variable ?

Thanks for sharing your solution!

Yes, the bug is exactly what you pasted there. There should be:

  1. explicit way to declare that I want whatever is written into this input field to be treated as a number
  2. by default, automatic inference of the bound value type, so that if I bind a Number type value, my input is treated as a number.

This should be acheived with a dropdown for “Input field type”, that has options

  • Inferred from Value field binding type (default selection)
  • Always text
  • Always number

Hoping to get to this (among all the other things :smiley: ) soon!

1 Like

This hack no longer works. All I want to do is add two user input numbers together and there doesn’t seem to be any way to do it because of this glitch. I’ve set every possible parameter to ‘number’ where applicable and nothing works, not even the NUMBER(variable) method.

Do you have any intention of fixing the issue by chance? I rather thought I had found a program that would let me make the calculations I need, but perchance I need to keep looking?

Thank you kindly. I do hope that one way or another Appgyver succeeds in the long run!