The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Round with awk AnnaLynn Shell Programming and Scripting 1 05-06-2008 11:55 AM
round in KSH here2learn Shell Programming and Scripting 6 07-18-2006 09:18 AM
how to round a value kotasateesh UNIX for Dummies Questions & Answers 2 02-08-2006 01:38 PM
Cannot adjust division jav_v Filesystems, Disks and Memory 1 08-20-2002 05:50 AM
division problem inquirer Shell Programming and Scripting 3 04-02-2002 07:03 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-15-2007
Registered User
 

Join Date: Feb 2007
Posts: 21
Round with division command

Hi I want to create a list of percentages but the shell script is bugging me.

If if I want to resolve the percentage of the quota used I get 0 because the schell script rounds by default.

Example

Code:
w1=860
w2=1024
w3=$((($w1/$w2)*100))

Echo $w3 gives 0
When I divide w1 by w2 the result is 0,83!

Can somebody help me?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-15-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
w3=$( echo "scale=6; ( $w1 / $w2 ) * 100" | bc )
Reply With Quote
  #3 (permalink)  
Old 02-15-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,593
some scale

Code:
c=`echo "scale=6; $a / $b" | bc`
Reply With Quote
  #4 (permalink)  
Old 02-15-2007
Registered User
 

Join Date: Feb 2007
Posts: 21
bc | command not found

Hi when i use w3=$( echo "scale=6; ( $w1 / $w2 ) * 100" | bc )

I get the error Command not found
Reply With Quote
  #5 (permalink)  
Old 02-15-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,593
check whether the directory in which bc lives is in the $PATH

usually it should be as

/usr/bin/bc
Reply With Quote
  #6 (permalink)  
Old 02-15-2007
Registered User
 

Join Date: Feb 2007
Posts: 21
Locate bc

bc is not located in the usr/bin folder. Is there an easy way to locate the command so I can put it in the path?
Reply With Quote
  #7 (permalink)  
Old 02-15-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,593
Could you please let us know the operating system that you are using ?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0