Total of Decimal quantifies gives only integer part

I am doing some calculations to find the ratio of market Cap for each stock vs total market cap for all stocks. I am getting the stockQty and mktCap correctly for individual stocks. Both of these variables have 4 and 6 decimals respectively.

I am dividing stockQty by 10000 and mktCap further by 100 otherwise the integer part is going beyond 7 digits. As I need only the proportion for each stock, this division will not affect the end result.

When I check totalQty and totalMktCap after the loop, they contain only the integer part. Both these variables have only zeroes after the decimal point. The integer part is indeed correct, but I am not able to understand why the decimal part has only zeroes. It is just not possible that all the decimals of stockQty and mktCap add up to give a whole number

Following is the code snippet:

for() //iterate through list of symbols
{
   stockQty = symStockQty/10000; //Dividing to accomodate integer part in a double variable
   totalQty = totalQty + stockQty;
   Cl = Foreign(sym, "C");
   mktCap = Cl[BarCount-1] * stockQty / 100; //Dividing again to acccomodate integer part in a double variable;
   totalMktCap = totalMktCap + mktCap;
}
  1. Your code is incomplete and incorrect (for loop is wrong)
  2. http://www.amibroker.com/kb/2010/07/20/about-floating-point-arithmetic/

You are correct, I haven’t given the full code, but only the main part. My code is working and I do have certain conditions inside for loop to iterate through list of symbols. I had already referred to the link in point 2 during development.

I was able to resolve the issue. I had to further divide the numbers such that integer part after addition had only 6 digits or less. Now things are working fine.