deciaml places

Hello All,

Can anyone please tell me how do i define the variable as decimal.
Below is my script. After division i get a whole number where as i want to see the decimal places also..

TABLEAVG=`expr ${TABLECHARS}/${TABLELINES} | bc`

EG: if TABLECHARS= 1280 and TABLELINES=44 the
O/P is 29.0909

I want the decimal to be diplayed on the screen..whereas what i get now is 29

I want the output with the decimal places to be displayed

TABLEAVG=`echo " $TABLECHARS/$TABLELINES" | bc -l`
printf "%5.4f" $TABLEAVG

printf -- the %5.4 controls the number of decimal places - otherwise you can a get a lot whith just

echo $TABLEAVG

or you can define your own 'scale' for 'bc':

TABLEAVG=`echo "scale=2; $TABLECHARS/$TABLELINES" | bc -l`

With zsh:

% ((TABLEAVG=1280./44));print $TABLEAVG
29.0909090909

If you want to specify how many significant digits you want in the output (4 in the example below):

% declare -F4 TABLEAVG='1280./44';echo $TABLEAVG
29.0909

With ksh93(or dtksh on Solaris, for example):

$ typeset -F4 TABLEAVG='1280./44';echo $TABLEAVG
29.0909

Thanku so much...it works...

But i have a problem...
I have given an if statment stating that if its whole number output the "TABLEAVG"
else
value with decimal...

if [ $TABLEAVG == 29 ]
then
echo "The file is good with count of comma per line : $TABLEAVG"
else
echo "The file is corrupt with commas : $TABLEAVG"
fi

If the output is 29, it displays 29.00 because i have given the sacle..is there any workaround for this..

thanks

I guess I don't understand what it is that you really want: you want an integer representation OR you want float with a 'scale'?

I need both..
Eg: as per the script if the tablechar=58 and the tablelines=2 the output after division is 29(tableavg)
now, in the IF statment

if [ $TABLEAVG == 29 ]
then
echo "The file is good with count of comma per line without any decimal point : $TABLEAVG"
else
echo "The file is corrupt with commas having decimal values : $TABLEAVG"
fi

i dont want the decimal places if the is it 29.000(the zeros have to be eliminated), where as if the o/p is 29.09 i want that ouput with decimal values..

thanks in advance
and say for eg: if the output is with