You are viewing a single comment's thread. Return to all comments →
#!/bin/bash read expression result=$(echo "scale=4; $expression" | bc -l) if (( $(echo "$result >= 0" | bc -l) )); then rounded_result=$(echo "$result + 0.0005" | bc -l) else rounded_result=$(echo "$result - 0.0005" | bc -l) fi final_result=$(echo "scale=3; $rounded_result / 1" | bc -l) # dividing the rounded_result by 1 to ommit the zero at end (if there's any) echo $final_result
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Arithmetic Operations
You are viewing a single comment's thread. Return to all comments →