I have a database with a table, containing two integer fields.
When I try to get a percentage (fieldA / (fieldA+fieldB)), the value is 0.
double percentage = fieldA+fieldB // WORKS; 5+5=10
double percentage = fieldA / (fieldA+fieldB) // DOES NOT WORK; 5+5=0
So what’s the problem here? Thanks..
When you do
fieldA / (fieldA+fieldB)you get 5/10, which as an integer is truncated to 0, you have to do double division if you want 0.5 as a result.i.e. something like this: