I'm trying to use BC to calculate some numbers in a shell script.
I want to have the numbers rounded off to 1 decimal place.
for example:
initsize=1566720
zipsize=4733
I'm trying to get the ratio between them. the equation is:
(($initsize-$zipsize)/$initsize)*100
so I'm trying to do this:
echo "scale=1; (($initsize-$zipsize)/$initsize)*100" | bc
but the answer is coming out as 90.0 instead of 99.6
it's obviously because the first part in the brackets is being rounded off before getting multiplied by 100.
I tried plsitting it up to work out hte first bit at 3 decimal places, then multiplying it by 100 with 1 deciaml place. but it still showed up with 3 decimal places.
$ bc
bc 1.03 (Nov 2, 1994)
Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
scale=9
(1566720-4733) / 1566720
.996979039
scale=1
(1566720-4733) / 1566720
.9