 Fix for expression giving 0% or missing decimal part

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 column values:

([Correct Answer Count] / DECIMAL([Question Count]))

or:

([Correct Answer Count] / ([Question Count] * 1.0))

THE DETAILS

The Number column type represents integers, which are whole numbers, numbers without a fractional component. A Number value has no decimal point.

When one Number value is divided by another Number value, AppSheet assumes you want the result to also by a Number value. If the result has in a fractional component (something after the decimal point), that fractional component is discarded entirely, leaving only the whole number component (the part before the decimal point).

If one or both of the values in a division operation is a Decimal value, AppSheet assumes you want the result to be a Decimal value as well, and will preserve any fractional component in the result.

The DECIMAL() function can be used to convert a Number value to a Decimal value. Multiplying a Number value by 1.0 (a Decimal value) has the same effect.

5 Likes

Thanks for the explanation and tip how to work around this @Steve! Since Appsheet knows we are dividing two “numbers”, and that there is a decimal remainder, would be a lot less confusing to return the decimal automatically. Maybe a request for the backlog?

1 Like