I learn this very useful trick from http://www.zazzybob.com/bin/calc.html
$ cat mybc
#!/bin/sh
( echo scale=2; echo "$@" ) | bc
exit 0
scale=The value of the scale function is the number of digits after the decimal point in the expression.
Now normal calculations became very simple with bc (make mybc an alias for bc or use separately):
$ mybc 34256+123456
157712
$ mybc 123456-34256
89200
$ mybc 123456*34256
4229108736
$ mybc 123456/34256
3.60
$ mybc 123456+34256*2
191968
No comments:
Post a Comment