-1

How can I multiply by decimal numbers and get the result in decimal?? How can the code be modified to meet these two conditions? enter image description here

1 Answers1

0

You could call the desk-calculator program to do the arithmetic:

v1 = 3
pi = 3.14
$ echo "Area of Circle =" $(dc --expression="$pi $v1 * $v1 * p")
Area of Circle = 28.26

In case you aren't familiar with it, dc uses reverse-polish syntax:

  • stack $pi
  • stack $v1
  • replace the top two numbers with their product
  • stack $v1
  • replace the top two numbers with their product
  • print the top of the stack

These are equivalent expressions:

$ echo "Area of Circle =" $(dc --expression="$pi $v1 * $v1 * p")
Area of Circle = 28.26

$ echo "Area of Circle =" $(dc --expression="$pi $v1 2 ^ * p") Area of Circle = 28.26

$ echo "Area of Circle =" $(dc --expression="$v1 2 ^ $pi * p") Area of Circle = 28.26