bc : 2 little tricks you’ve ever wanted to know

If you’re looking for a good calculator on Linux / Unix, you can use bc. bc is “an arbitrary precision calculator” supporting bignumbers and many operators … well it will mostly do whatever you want (check the fine documentation).

Anyway, about those 2 little tricks I promised :

  1. change the scale variable (eg : scale=10) to set “the total number of digits after the decimal point”. Defaults to 0 -> Not cool.
  2. use the last variable to recall the last value you computed -> Cool.

That was it ! This is what I always need and forget, so I decided to blog it once for all…

If you really don’t know bc yet, give it a try !

Update: you can start bc with a default scale of 20 by using the “-l” option on the command line … (Thanks to Luke).

2 thoughts on “bc : 2 little tricks you’ve ever wanted to know”

  1. Regarding the first tip – just run bc with -l:

    bc -l

    It puts the calculator in the floating point mode, and enables all the advanced math functions.

    I use bc all the time. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *