Hi all,

I am trying to use BigNumber in my game but am getting stuck. To try and wrok out where I am going wrong I’ve got some really basic test code that doesn’t seem to do what I expect? I am trying to find the average of lst=[1,2,3,4,5,6,7,8] which I would expect to be 4.5 but my code returns 4?

I am including #include <bignum.h> so I guess I’m doing something silly but can’t see what it is? Thanks for any advice.

Sum is 36 Count is 8 Average is 4

  : tstAction
  verbPhrase = 'tst'

local lst=[1,2,3,4,5,6,7,8];
local sum=0;
local cnt=0;
local avg = new BigNumber(0 , 2); 

foreach(local cur in lst)
"Sum is <<sum>> Count is <<cnt>> Average is <<avg>> ";

Essentially, by writing the list in integers with no decimals, you are telling bignumber to round to an integer value. Why it’s rounding down instead of up I’m not sure, but if you want it to display 4.5, all of your values must be of the same precision. Instead, write:

local lst=[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0];

that will fix the problem.