bc (command line calculator)

Why use a restricted graphical calculator when you have an arbitrary precision calculator language on the command line? Fire it up by typing bc. This will give you a new command prompt where you can enter arithmetic expressions much like you're used to, e.g. 1+2 or 3*7. If you need the result of the last expression calculated, use the keyword last, for example:

1+2

3

last+7

10

You entered 1+2 and bc gave you the result 3. Then you added 7 to this intermediate result by typing last+7.

bc displays only one or two decimal places by default when doing floating point arithmetic. You can change this like so:

scale=4

This will make bc print up to 4 decimal places. Since bc is an arbitrary precision calculator language, the scale can be as large as 2147483647! You can save your favorite scale value by adding the following line to your ~/.bashrc configuration file:

export BC_ENV_ARGS=“$HOME/.bc_settings”

In the file ~/.bc_settings (you can use any other file name), save your desired scale value, for example:

scale=8

Every time bc starts, it evaluates the file given by BC_ENV_ARGS.