We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Linux Shell
- Bash
- Arithmetic Operations
- Discussions
Arithmetic Operations
Arithmetic Operations
Sort by
recency
|
222 Discussions
|
Please Login in order to post a comment
read user_input printf "%.3f" user_input")
read X result=X" | bc) printf "%.3f\n" $result
I ended up having to do
but I think I should have had the correct answer with just scale=3 and echoing $result without using printf. I wonder why?
where 1st line will take the expression, and 2nd line will read the expression using echo $exp, perform the calculations using bc -l and print the result upto 3 decimal places using printf "%.3f"