Right now I am working on an assignment that involves advanced piping, and one of the questions involves calculating a percent and shortening it to 3 decimal places. I've managed to calculate the percent:
echo "$ERRORS" / "$TOTAL" \* 100 | bc -l
which gives the correct output: 2.64905226881102814400
ERRORS and TOTAL are both environment variables containing integers.
But I don't really know how to modify this command to only output 2.649 instead of the full number. I know there is a way to use something called scale with bc to shorten to a certain number of decimal places but I tried echo scale=3; "$ERRORS" / "$TOTAL" \* 100 | bc -l
and it didn't work.
What am I doing wrong?
| xargs printf '%.3f\n'
– Paul_Pedant Jul 24 '20 at 14:37