Floating point number operations in Linux

In this topic, let us learn how to perform operations on floating point numbers in Linux.

We know that we can use below ways to perform operations on Integer numbers.

  1. a=`expr $b + 1`
  2. a=$((b+2))
  3. let a=b-1

If you try to use floating point numbers in above commands, you will get error saying “non-integer argument”

In Linux, we can use “bc” command to perform operations on floating point numbers as shown in below examples.

  1. a=$(echo 2.3 + 3.4 |  bc)

 

You may also like...