Calculation - Result not accurate if numbe too big

Dear all,

Below is my script,

totalCount=57006427
totalSummCount=1207590
let percentageSumTmp1=${totalCount}-${totalSummCount}
let percentageSumTmp2=${percentageSumTmp1}*100

The expected result for percentageSumTmp2 should be (5579883700),
but when I execute the script in unix env i get 1284916404 ..
If I remove 1 digit number of the totalCount , then i able to get correct result :frowning:

anyone , know how to fix it ?

Many thanks.

I do not really know... Perhaps because of shell limits.
Though you could do the operations in HEX:

totalCount=0x365D95B
totalSummCount=0x126D26
let percentageSumTmp1=${totalCount}-${totalSummCount}
let percentageSumTmp2=${percentageSumTmp1}*100

echo $percentageSumTmp2

This returns "5579883700"... :slight_smile:

How about using bc ? See How to perform calculations using numbers greater than 2150000000.

Sure! It's usually available... I suppose awk would also do the job... :slight_smile: