Arithmetic Operations

Sort by

recency

|

237 Discussions

|

  • + 0 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
    
    
        
    
  • + 0 comments

    SOLVED

    start of script

    !/bin/bash

    read expression result=expression" | bc -l) rounded_res=result") echo $rounded_res

  • + 0 comments

    read expr

    result=expr" | bc -l)

    printf "%.3f\n" "$result"

  • + 0 comments

    read input printf "%.3f\n" echo "$input" | bc -l

  • + 0 comments

    this works totally fine

    result=$(echo "$expression" | bc -l)
    printf "%.3f\n" "$result"