0

code is not working. I think this might have to do with the floating point in the constant " TAX_FACTOR=0.0070. The code is:

ShowTax() {
           local TAX_FACTOR=0.0070
           echo "Enter the property's value."
           read propertyValue
          tax=$((expr $propertyValue*$TAX_FACTOR )) #there is a problem
          echo "The property tax is:" "$tax"      
          }

  # Main
    echo " Enter lot number of property or 0 to end"
    read lotNumber

    while(( $lotNumber != 0 ));do 
       showTax
       echo "Enter the lot number for the next property or 0 to end"
       read lotNumber
   done
Rafaf Tahsin
  • 7,652
  • 4
  • 28
  • 45
  • QuickNote: you don't have to use $ inside double parenthesis. (()) - https://www.tldp.org/LDP/abs/html/dblparens.html – Rafaf Tahsin Mar 10 '20 at 04:44
  • 1
    `bash` (and `expr`) cannot deal with floating-point numbers. At all. See ["Arithmetic with floating point"](https://stackoverflow.com/questions/27586277/arithmetic-with-floating-point), ["How to compare two floating point numbers in Bash?"](https://stackoverflow.com/questions/8654051/how-to-compare-two-floating-point-numbers-in-bash), and ["How do I use floating-point division in bash?"](https://stackoverflow.com/questions/12722095/how-do-i-use-floating-point-division-in-bash) – Gordon Davisson Mar 10 '20 at 04:44
  • In short: `tax=$( bc <<< "scale = 4; $propertyValue*$TAX_FACTOR" )` – Abelisto Mar 10 '20 at 05:14

0 Answers0