Bash decimal arithmetic?

Charles Curley charlescurley at charlescurley.com
Thu Nov 11 03:33:44 UTC 2004


On Wed, Nov 10, 2004 at 10:18:32PM -0500, Graham Campbell 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.

Alternatively, scale your numbers. i.e. if you need two decimal
places, run everything internally as integers 100 times the "real"
value, and display with the decimal point in the correct place. Old
assembly language programmers' trick.

-- 

Charles Curley                  /"\    ASCII Ribbon Campaign
Looking for fine software       \ /    Respect for open standards
and/or writing?                  X     No HTML/RTF in email
http://www.charlescurley.com    / \    No M$ Word docs in email

Key fingerprint = CE5C 6645 A45A 64E4 94C0  809C FFF6 4C48 4ECD DFDB
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/fedora-list/attachments/20041110/d6c71b82/attachment-0001.sig>


More information about the fedora-list mailing list