bc
A calculator program with arbitrary precision that does the decimal maths bash itself cannot.
In more detail
Pipe an expression into it, as in echo "scale=2; 10 / 3" | bc, where scale sets the number of decimal places. bc -l loads a maths library and sets a default scale of 20.
Example
echo "scale=2; 10 / 3" | bcRelated terms
- floating-point number — A number with a fractional part stored in binary, which can only approximate most decimal values.
- integer arithmetic — Maths on whole numbers only, which is all bash can do itself: 7 / 2 gives 3, with the remainder dropped.
Taught in
- Arithmetic: Double Parentheses, let And bc — Bash Scripting & Command Line Automation