Hello,
Im trying to work on a small script for a formula converting temperatures, Celsius to fahrenheit.
I have a formula, and it works.... it works every way I try it. But it keeps giving me the wrong results every time with expr.
The formula for C to F would be:
divide by 5, multiply by 9, add 32.
So..... simple code here
read c
f= `expr $c / 5 \* 9 + 32`
echo $f
The problem is, its never correct because expr can't seem to add the decimals right.
For instance 32 degrees celcius.
f=`expr 32 / 5 \* 9 + 32`
gives me 86 for some reason. It should give 89 (or 89.6)
I have also tried it another way, which seems odd, but still should give correct results.
f=`expr 9 / 5 \* $c + 32`
Again, I have tested, it should be 89, but it ends up giving me 64.
Because expr 9 / 5 is giving me 1, instead of 1.8
So 1 * 32 = 32 + 32 = 64.
It should be 1.8 * 32 = 57.6 + 32 = 89.6
It seems like my problem is the fact that expr won't account for decimals.
Is there a way to get it to acknowledge the decimals?
Or is this not possible with the expr command?
Thanks a lot