# The Problem

In certain dialects, including Postgres and Redshift, if you perform a calculation between integers (dividing counts for instance) it will return an integer, even if the result would be a decimal in normal math. You might make a dimension like this:

measure: sold_ratio {

type: number

sql: ${sold_count} / ${total_count} ;;

value_format: "0.00" # Number with exactly 2 decimals (1.23)

}

measure: sold_percent {

type: number

sql: 100 * ${sold_count} / ${count} ;;

value_format: "0.00"

}

Note that the ratio is returning zero, and the percent does not have its decimal places populated. If we do the math, it becomes clear this is not correct.

# The Solution: Cast field as a Floating-Point Number

If the calculation is multiplied by a non-integer, the values will cast as floats, and decimals will be returned as expected. You can multiply the numerator by a decimal number (like 1.0 or 100.0) to force SQL into returning a decimal result.

## For example:

measure: sold_ratio {

type: number

sql: 1.0 * ${sold_count} / ${total_count};;

value_format: "0.00"

}

measure: sold_percent {

type: number

sql: 100.0 * ${sold_count} / ${count};;

value_format: "0.00"

}