Skip to content
Advertisement

decimal value is not printing in bash?

I want to evaluate the expression and display the output correct to 3 decimal places i tried with below code but it is not working help me how to do that in bash.

echo -e "Enter expression to calculate : c"
read num
let a=num
printf '%fn' "$a"

Input :  5+50*3/20 + (19*2)/7

Output :  17.000000

Desired Output : 17.929

Advertisement

Answer

With bc:

echo 'scale=3; 5+50*3/20 + (19*2)/7' | bc -l

Output:

17.928
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement