A virtual column gives 0.0000 from formula 1/2

The virtual column is decimal type having 4 decimal digits.

given result is

3X_c_5_c548c9a0d7120d86d2b4e9ccf41f1bffe335f906.jpeg

The expected result is 0.5000.

Why?

1 Like

Please try

1/2.0000 as app formula.

2 Likes

Thanks but regret to say that it does not answer my question.

Division with integers ( 1/ 2) , will have integer result. (0)

Dividing by 2.0000 brings in decimal division. Number of decimal points in denominator will give decimal points in answer. Division by 2.0 will result in 0.5

4 Likes

Read the document I refered to .

2 Likes

Thank you very much.

1 Like

Fix for expression giving 0% or missing decimal part Tips & Tricks ?

Trying to divide two numbers to get a percentage but always getting 0? Trying to divide two numbers but losing the numbers after the decimal point? TRY THIS Convert one or both of the values in your division expression to a Decimal value, either by: (1) wrapping the value in the expression with the DECIMAL() function; (2) multiplying the value in the expression by 1.0; or (3) changing the column’s type to Decimal if suitable to the app. FOR EXAMPLE If computing a percentage from two Number co…

2 Likes

Thanks Steve. If an expression contains [columns], the result seems ok. In my case there was pure numbers with operators, adjusting the decimal points of virtual column does not help showing the expected value.

Anyway that was just my experiment, there is no use in real apps.

Swoopy:

adjusting the decimal points of virtual column does not help showing the expected value

What does this have to do with anything?

1 Like

All this started from my curious of how AppSheet prioritizes the math operators in calculations (I have not seen any documentations mention about it).

To check if 1-1/2 returns 0.5 (like scientific calculators) or 0 ? I created a virtual column to test it. The result was 0. But I could not conclude that the result 0 was from calculation or from displaying behavior.

If AppSheet does scientific way, I will not use extra ( ) in my expressions.

1 Like

AppSheet applies common math order of operations, but order of operations is not the problem with your expression.

2 Likes

To make things clear, what are the results from this following expressions in AppSheet?

[column a]-[column b]/2 =?

[column a]-([column b]/2) =?

([column a]-[column b])/2 =?

If the values of [column a] and [column b] are 1.

What are the column types of column a and column b?

2 Likes

Absolutely decimal type.

Steve:

What are the column types of column a and column b ?

Swoopy:

Absolutely decimal type.

Then I would expect:

  • [column a]-[column b]/2 to give 0.5

  • [column a]-([column b]/2) to give 0.5

  • ([column a]-[column b])/2 to give 0

But if they are instead of type Number:

  • [column a]-[column b]/2 would give 1

  • [column a]-([column b]/2) would give 1

  • ([column a]-[column b])/2 would give 0

2 Likes

Thank you

2 Likes