Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

floating point number handling in shell script 1

Status
Not open for further replies.

inunix

Technical User
Jul 30, 2002
53
US
Here is my input..
eg:
X=`cat abc|wc -l`
Y=`ls *.*|wc -l`
when i divide X/Y, sometime I'm getting results as 0.
I need the output in 2 decimal paces like 0.22 or whatever.

How do achieve this in shell scripts.?

Thanks in advance
 
Try something like this:
Code:
echo "$X" "$Y" | awk '{printf "%.2f\n",$1/$2}'

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top