Round with division command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Round with division command
# 1  
Old 02-15-2007
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?
# 2  
Old 02-15-2007
Code:
w3=$( echo "scale=6; ( $w1 / $w2 ) * 100" | bc )

# 3  
Old 02-15-2007
some scale

Code:
c=`echo "scale=6; $a / $b" | bc`

# 4  
Old 02-15-2007
bc | command not found

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

I get the error Command not found
# 5  
Old 02-15-2007
check whether the directory in which bc lives is in the $PATH

usually it should be as

/usr/bin/bc
# 6  
Old 02-15-2007
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?
# 7  
Old 02-15-2007
Could you please let us know the operating system that you are using ? Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Round values only when it's numerics

Hi, all I have a field in a file looks like this(hundreds of lines): inf 1.24101 -0.185947 -0.349179 inf 0.126597 0.240142 -0.12031And what I expect is: inf 1.241 -0.186 -0.349 inf 0.127 (7 Replies)
Discussion started by: nengcheng
7 Replies

2. Shell Programming and Scripting

Round up the decimals

Hi All, I would like to do the following in the shell script 561.76 to 562 I tried using this echo 'scale=0; 749 * 75 /100 ' | bc but just returned only 561 Please help me . I appreciate your help Thanks rajeevm (13 Replies)
Discussion started by: rajeevm
13 Replies

3. UNIX for Dummies Questions & Answers

Help in division

hi, The below commands result only the whole number(not giving the decimal values). pandeeswaran@ubuntu:~$ echo 1,2,3,4|sed 's/,/\//g'|bc 0 pandeeswaran@ubuntu:~$ echo 1000,2,3|sed 's/,/\//g'|bc 166 How to make it to return the decimal values? Thanks (5 Replies)
Discussion started by: pandeesh
5 Replies

4. Shell Programming and Scripting

division by zero

Hello, I am searching for a way to calculate for example 10/100 within a shellscript and the result should be 0.1 and not just 0. Every alternative i tried just results 0 Thank you in advance 2retti (6 Replies)
Discussion started by: 2retti
6 Replies

5. Shell Programming and Scripting

Round off the a Decimal value.

HI, I have a script which is used to calculate the Memory & CPU utilization a server. memx=`ssh -l siebel1 ${f} /usr/sbin/prtconf|grep -i 'Memory size'|tr -s " "|/usr/xpg4/bin/awk -F" " '{print $3 * 1024}'` v5=`ssh -l siebel1 ${f} vmstat 1 2 | tail -1 | tr -s " " | /usr/xpg4/bin/awk -v... (3 Replies)
Discussion started by: dear_abhi2007
3 Replies

6. Shell Programming and Scripting

Round with awk

Hi, I have a problem. Basically I dont know how to use awk. I have a script (below) which works fine. What I want to do is somehow "pipe" in the input say 4.5 and have it give the anwer, I dont want ot have to type it in, since it will be running in a script. Any ideas how to do this???? ... (1 Reply)
Discussion started by: AnnaLynn
1 Replies

7. Shell Programming and Scripting

Round the column value :

Hi .... Iam having the file ....in which 3rd column is numerical having 8 decimal part... i want that to cut to 2 decimal part ... Source File : E100|0|19940.10104030|0|1ABC E103|1|19942.10195849|3|0ABC E100|0|19943.10284858|0|1ABC I want to be ...... Reulst: ... (4 Replies)
Discussion started by: satyam_sat
4 Replies

8. Shell Programming and Scripting

round a number

In a shell script - How do I round a decimal number (contained in a variable) to the nearest whole number? (2 Replies)
Discussion started by: achieve
2 Replies

9. Shell Programming and Scripting

round in KSH

Is there an easy way to round a number up in Korn shell? ie. 10.4 --> 11 Thanks. (6 Replies)
Discussion started by: here2learn
6 Replies

10. UNIX for Dummies Questions & Answers

how to round a value

Hello, In a unix shell script,i want to round a variabele to a nearest number Ex: set count=104.4 How can i round that to 105.? Thanks, Sateesh (2 Replies)
Discussion started by: kotasateesh
2 Replies
Login or Register to Ask a Question