I have an expression "5+50*3/20 + (19*2)/7"
I need to round it up to 3 decimal places. The answer to this is 17.92857142857143
. When I use the script below it is giving me 17.928
. The answer should be 17.929
.
read exp
echo "scale=3; $exp" |bc -l
And one more question is how to use printf
to do the same task
17.928
may or may not be correct. – muru Dec 08 '14 at 14:51echo $(printf "%.3f\n" $(echo " scale=4; $exp" |bc))
I used this and got the ans. But will see any one comes up with alternate method. I am learning bash so using it. – WannaBeCoder Dec 08 '14 at 14:59