On Sun, 2005-06-12 at 23:52 -0600, Archaic wrote: > I've been playing with bc a bit and the phrase used to describe it is > "arbitrary precision calculator language". So either I'm just not > getting it, or this thing isn't precise as it doesn't round when you go > from a scale of say 7 to 6. Does it require creating macros just to > round? If so, does anyone one know of a good command line calculator > that rounds to the length specified? So far the three I've pulled from > freshmeat that seemed to fit the description were not very good. One > couldn't handle piping the expression to it, so it won't do for > scripting purposes.
You got Python installed? I find that to be a handy enough calculator most of the time. Try something like: >>> print "%.2f" % round(123.456789, 2) 123.46 Is that what you're looking for? It's a little bit of a hack since the round() function returns a floating point number like 123.45999999999999, which the "%.2f" formats correctly to 2dp. If you want to run off a shell script, try something like the following: $ x=123.456789 $ dp=2 $ python -c "print '%.${dp}f' % round(${x},${dp})" 123.46 Hope this is helpful... Simon.
signature.asc
Description: This is a digitally signed message part
-- http://linuxfromscratch.org/mailman/listinfo/blfs-support FAQ: http://www.linuxfromscratch.org/blfs/faq.html Unsubscribe: See the above information page