Bash decimal arithmetic?

Dean Maluski dmaluski at n1ety.com
Thu Nov 11 04:17:49 UTC 2004


I'm actually doing that now.
One of my HDTV transmitters at work has a reflected power of 0.5%.
I'm using snmp to get the data in milliwatts then dividing the number
for total and reflected power with a static value to achieve a
percentage. I reduced the reflected divisor by 10. I then display a "0."
on a web page. If it went out to 1% reflected power it would display as
"0.1000" I think the bc tip will get me where I want to go.
Thankyou!

On Wed, 2004-11-10 at 22:33, Charles Curley wrote:
> 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.




More information about the fedora-list mailing list