Multiply floats in bash script
I have a bash script with the following line where $timestep is a decimal number.
t=$timestep*$i echo $t gives the value "0.125*2" for example instead of "0.250". How do I change this?!? |
Try t=`expr $timestep*$i`.
Also, see the Advanced Bash Scripting Guide, chapter 15 on arthmetic expansion. |
Quote:
$timestep=0.125 * $i=2 You are not going to get bash to use 0.125 as a number in an arithmetic expression. -------------------- Steve Stites |
To do floating point calculations in a shell script you can invoke awk, e.g.
Code:
timestep=0.125 |
hey guys, thanks for the help but actually i figured it out to be:
t=$(expr $timestep*$i | bc) i have not tried the awk method, but the other ones did not work for me. |
It should be
Code:
t=$(echo $timestep*$i | bc) |
All times are GMT -5. The time now is 08:37 AM. |