May 2018
Beginner
332 pages
7h 28m
English
In the Bash shell, we can only perform integer arithmetic. If we want to perform arithmetic involving a floating point or fractional values, then we will need to use various other utilities, such as awk, bc, and similar.
Let's see an example of using the utility called bc:
$ echo "scale=2; 15 / 2" | bc
7.50
For using the bc utility, we need to configure a scale parameter. Scale is the number of significant digits to the right of the decimal point. We have told the bc utility to calculate 15 / 2, and then display the result with the scale of 2.
Another example is the following:
$ bc
((83.12 + 32.13) * 37.3)
4298.82
Many things can be done with the bc utility, such as all types of arithmetic operations including ...