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: arithmetic, bc, floating point, Linux, shell, UNIX
March 19th, 2009 at 4:28 pm
Great, thanks Francois. You will not believe how helpful this will be. Now the challenge is to remember it!