Assigning a shell variable as a float

I'm confused as to how to handle floating point numbers in shell scripts. Is there a way to convert a number (string) read into a shell variable so that it can be used as a floating point decimal for calculation purposes? Or am I stuck with integrating C or Perl into my script?

Ex:

--input

read Number1 --number entered for example is .20
read Number2 --number entered for example is .30

Total

--or--

let Total=$Number1 + $Number2 --which I know only works for integers.

--output

printf "%0.2f" $Total=$Number1 + $Number2

I essentially want a total of two decimal numbers that have been read from the command line (i.e. .20+.30=.50 or Total), but printf will not compute the calculation as I have it coded. I'm at a loss...

Any insight would be appreciated,

--S

try eval in your exprestion.

ksh93 has support for floating point. The more common ksh88 does not. I don't think that any other shell supports floating point, but maybe I'm wrong about that.

If you don't have ksh93, you can use bc like this:

x=`echo 1.23 + .90 | bc`
echo $x

With ksh, you can even set up bc as a coprocess and then do many calculation with one instance of bc running. But with other shells, the above is all there is.

Thanks much!

The piped bc command worked like a charm!

--S