Help with numeric manupulations

I want to calculate the following expression in script:

val=179584.0
($val *3*16384)/(1073741824)

$val will have a floating value.

Thanks!

I tried with following:

 
 n=$(echo |awk '{ print $val*3*16384 }')
n=$(echo |awk '{ v=$val; print $v*3*16384 }')
expr $val \* 3.0 \* 16384.0

Hi,

try:

echo "($val *3*16384)/(1073741824)"|bc  -l

worked.... anyway to make the final solution to a whole number?
We can use cut command but any other solution?

use only

bc

without

-l
1 Like

Thanks for the help.

---------- Post updated at 09:05 PM ---------- Previous update was at 08:33 PM ----------

How can we limit the number of digits after the decimal.
If the above expression generates 8.220703125, how can we display it as 8.220

echo 'scale=3 ;(179584.0*3*16384)/(1073741824)' | bc

If you want to do this all in awk:

awk -v val="$val" 'END { printf("%.3f", (val*3*16384)/1073741824); }' /dev/null

x=`echo 'scale=3 ;($val*3*16384)/(1073741824)' | bc`
syntax error on line 1 stdin

your version of bc doesn't support scale.

Try the awk code.

change

;

with

\n

and use

echo -e

Not all systems have echo -e, either. Try printf.