I want to calculate the percentage of a few numbers upto 2 decimal places. Since my total count is pretty high, dividing 100 by it gives a really small number (0.000..) so for this step I have a large scale of 10. The second step where i multiply the resulting number to calculate the percentage uses scale as 2, but it is ignored as bc uses the first scale of 10. This is the code I have:
mul=$(bc <<< "scale=10; (100/$t)")
while read -r num var
do
perc=$(bc <<< "scale=2; ($num*$mul)")
printf "$var\t$num\t$perc\n" >> ofile
done < counts
How can I get the second calculation to follow the scale and print up to 2 decimal places?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)