Bash decimal arithmetic?

Cameron Simpson cs at zip.com.au
Thu Nov 11 04:31:59 UTC 2004


On 22:18 10 Nov 2004, Graham Campbell <gc1111 at optonline.net> wrote:
| On Wed, 2004-11-10 at 21:22 -0500, Dean Maluski wrote:
| > Does bash have an option to do non integer math in scripts?
| > I need my exact decimal numbers.
| 
| An "exact decimal number" is a contradiction in terms. If you can
| specify the precision you wish to retain then use bc to do the
| calculations.

Of course, an "exact decimal number" is not a contradiction in terms.
2.5 is exactly 2.5. or course, _some_ decimal numbers are not storable
precisely in the _default_ internal binary format usually used for floats,
but that doesn't make the noption nonsensical.

But I'll second the suggestion that you use "bc" to do the work,
possibly/probably controlled from a shell script.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Gentle suggestions being those which are written on rocks of less than 5lbs.
        - Tracy Nelson in comp.lang.c




More information about the fedora-list mailing list