0

Within bash shell, I need to add numbers in the format : 0.13281E-04 and -0.79254E-04. So, in the script, I have:

  tt1=`echo $var_t1| sed -e 's/[eE]+*/\\*10\\^/'`
  tt2=`echo $var_t2| sed -e 's/[eE]+*/\\*10\\^/'`
  var_t=`echo "($tt1 + $tt2)/2.0" | bc -l`

which gives result as: -.000032986500000

Is there any straight forward way getting var_t as -3.29865E-05?

BaRud
  • 3,055
  • 7
  • 41
  • 89

1 Answers1

0

You can use the option -v of printf like so

printf -v var_t "%g\n" -.00003298650000
echo $var_t
hendrik
  • 1,902
  • 16
  • 14