in Education by
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)

1 Answer

0 votes
by
Format the numbers via printf: printf '%s\t%s\t%.2f\n' "$var" "$num" "$perc" >> ofile

Related questions

0 votes
    I want to calculate the percentage of a few numbers upto 2 decimal places. Since my total count is pretty high, dividing 100 by ... scale of 10. This is the code I have: mul=$(bc...
asked May 13, 2022 in Education by JackTerrance
0 votes
    Can you explain certain rules which you follow in doing link building?...
asked Mar 5, 2021 in Technology by Editorial Staff
0 votes
    how can i set a profile in zoom app in version 5.2or 5.1 whatever if your answer works i will mark u as the brainliest and follow u Select the correct answer from above options...
asked Dec 25, 2021 in Education by JackTerrance
0 votes
    What is a good practice to follow when you want to backup a local branch? A. Push to remote repo B. Move to another PC C. Create another copy D. None of the options...
asked Dec 20, 2022 in Technology by JackTerrance
0 votes
    A scenario is given to you below Read it and answer the questions that follow: Late one night, a car ran over a ... or a *****? Select the correct answer from above options...
asked Nov 12, 2021 in Education by JackTerrance
0 votes
    What are some best practices you should follow while using ServiceNow?...
asked May 25, 2021 in Technology by JackTerrance
0 votes
    Which websites do you follow for the latest updates in SEO?...
asked Mar 5, 2021 in Technology by Editorial Staff
0 votes
    The principal components are equal to left singular values if you first scale the variables. (a) True (b ... and answers pdf, Data Science interview questions for beginners...
asked Oct 28, 2021 in Education by JackTerrance
0 votes
    What will be the output of the following Python statement? >>>"a"+"bc" a) bc b) abc c) a d) bca...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    Express the Boolean Function, F (A, B, C) = AB + B’C’ in product of maxterm form. Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    mplemented by the circuit shown in the above right f uit diagram for expressions :dr ( a ) ( A ‘ + BC ) ( B ‘ + C’A ) Output Z Y Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    mplemented by the circuit shown in the above right f uit diagram for expressions :dr ( a ) ( A ‘ + BC ) ( B ‘ + C’A ) Output Z Y Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    The relation AD - BC = 1, (where A, B, C and D are the elements of a transmission matrix of a network ... Questions for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 13, 2021 in Education by JackTerrance
0 votes
    List strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    Liststrings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");...
asked Nov 8, 2020 in Education by Editorial Staff
...