Calculator commands in linux
Calculator commands in linux
Name
bc An arbitrary precision calculator language
2. Synopsis
bc [ -hlwsqv ] [long-options] [ file ... ]
3. Examples
bc is a very handy calculator. No need for GUI when using bc. Let’s see if it knows how to count. We will start with addition:
$ echo "34.7 + 345.655" | bc
How about subtraction:
$ echo "34.7 - 345.655" | bc
Multiplication:
$ echo "34.7 * 345.655" | bc
For division we need to specify a floating point as a “scale=x”, so for example to calculate with a floating point precision of 10, we should enter:
$ echo "scale=10; 10 / 3" | bc
The default precision is 0:
echo "10 / 3" | bc
Converting from decimal to hexadecimal number is even easier. All we need to specify is an output base ( obase ) and an input base ( ibase ). Let’s convert a decimal 1000 number to a hexadecimal number:
$ echo "obase=16; ibase=10; 1000;" | bc
Comments are closed.