This is integer division. When you divide integers, you get integers. so 1/2 = 0, 3/2 = 1 and so on. You have to convert either of your ints to a double. One way to do that is to multiply it by a double : longdouble percentWhite = 1.0*soundAmount/totPix*100;