How do I
perform arithmetic on floating point numbers?
With addition, bc returns
the decimal count of the greater of the arguments:
# echo "10.1 + 11.3" | bc
With multiplication/division, you can specify the decimal places: # echo "scale=5; 10.1 / 11.3"
| bc
Of course, within double quotes variables are accepted: # i=10.1; j=11.3
Notice that the above employs computational truncation, rather than rounding. Check your bc implementation for your results.
Have a Unix Problem
Unix Books :-
Return to : - Unix System Administration Hints and Tips (c) www.gotothings.com All material on this site is Copyright.
|