Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Yet another simple command line Calculator' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Yet another simple command line Calculator
Authored by: nicksay on Aug 08, '06 04:42:25PM
I've used a simliar function for a while now:
calc() {
    [[ $1 == *%* ]] && s=0 || s=5
    echo "scale=$s; $1" | bc -l
}
This limits the decimal precision to 5 places normally (which I prefer instead of 20), but switches back to integer precision when using the mod operator (i.e. 10 % 3).

The only requisite is to put your calculation in quotes. (i.e. calc '5 / 2').

[ Reply to This | # ]