Getting a decimal point from shell script division


total=1846047087
tt=1311
yyy=`expr $total / $tt`
echo "1 total = $yyy"
 ttt=`echo $total $tt  | awk '{print $1/$2}'`
 echo "2 total = $ttt"
...

1 total = 1408121
2 total = 1.40812e+06

However, I would like to receive 1408121.35 or 1408121.34 without rounding up
tommym121Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
woolmilkporcConnect With a Mentor Commented:
Hi,

 ttt=$(echo $total $tt  | awk '{printf "%.3f", $1/$2}')

For 2 decimal palces use "%.2f"

wmp


0
All Courses

From novice to tech pro — start learning today.