echo 'scale=4; 22/7' | bc -l

Category: Data Science & Analysis

echo 'scale=4; 22/7' | bc -l

Divide with 4 decimal places using bc

bc is an arbitrary-precision calculator language. The -l flag loads the math library, and scale=4 sets 4 decimal places for division, giving 22/7 as 3.1428. Without scale, integer division would truncate. The echo pipe feeds the expression into bc's stdin; the pipe symbol (|) connects the two commands.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.