Floating point arithmetic using bc

The bc shell utility that is available on most UNIX/Linux distributions defaults to integer arithmetic (i.e. throws away anything after the comma).

To prevent this, you can set the “scale” option in bc.

E.g., the following command will return 3.333:

echo “scale=3; 10/3″ | bc

Tags: , , , , ,

  1. Danie Loots

    Great, thanks Francois. You will not believe how helpful this will be. Now the challenge is to remember it!

Add a Comment