Published on

bc command-floating point operations



1 min read

The English spelling of bc is "Binary Calculator", which is a calculator language that supports arbitrary precision interactive execution. Bash has built-in support for the four arithmetic operations of integers, but does not support floating-point operations. The bc command can easily perform floating-point operations. Of course, integer operations are no longer a problem.

Syntax: bc [options]

Command parameters
-iForce into interactive mode
-lDefine the standard math library used
-wDefine the standard math library used
-qPrint normal GNU bc environment information

Arithmetic operations advanced operations bc command It can perform floating-point operations and some advanced functions:

[root@linuxstar ~]# echo "1.212*3" | bc 3.636

Set decimal precision (numerical range):

[root@linuxstar ~]# echo "scale=2;3/8" | bc .37

Calculate the square and square root:

[root@linuxstar ~]# echo "10^10" | bc 10000000000 [root@linuxstar ~]# echo "sqrt(100)" | bc 10