I am trying hard to compare two floating point numbers within a bash script. I have to variables, e.g.
let num1=3.17648e-22
let num2=1.5
No
It's better to use awk
for non integer mathematics. You can use this bash utility function:
numCompare() {
awk -v n1="$1" -v n2="$2" 'BEGIN {printf "%s " (n1=") " %s\n", n1, n2}'
}
And call it as:
numCompare 5.65 3.14e-22
5.65 >= 3.14e-22
numCompare 5.65e-23 3.14e-22
5.65e-23 < 3.14e-22
numCompare 3.145678 3.145679
3.145678 < 3.145679