Percentage calculation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Percentage calculation
# 1  
Old 04-11-2013
Percentage calculation

i am trying to get percentage : but not able to do it:

i tried :
x=1
y=2
z=`expr $x/$y*100`

it is not giving me result

can u pls help on this
# 2  
Old 04-11-2013
try multiplying by 100 first:
Code:
z=$((100*$x/$y))

or alternatively use bc:
Code:
z=$(echo "scale=2 ; ($x/$y*100)" | bc)

# 3  
Old 04-11-2013
i tried it :
Code:
z=$(echo "scale=4 ; ($x/$y*100)" | bc)

bt it is giving result : 33.3300
x=1
y=3

i want 33.33

Last edited by Franklin52; 04-11-2013 at 09:11 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 04-11-2013
Quote:
Originally Posted by Aditya.Gurgaon
i tried it :
z=$(echo "scale=4 ; ($x/$y*100)" | bc)

bt it is giving result : 33.3300
x=1
y=3

i want 33.33
That's because you set scale to '4' which is the number of digits right of the decimal point... So leave scale to '2' and it should work.
# 5  
Old 04-11-2013
it is coming 33.00

i need 33.33

how i will do it ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with awk percentage calculation from a file

i have a file say test with the below mentioned details Folder Name Total space Space used /test/test1 500.1GB 112.0 GB /test/test2 3.2 TB 5TB /test/test3 3TB 100GB i need to calculate percentage of each row based on total space and space used and copy... (9 Replies)
Discussion started by: venkitesh
9 Replies

2. Shell Programming and Scripting

Percentage calculation

Hi, I have a text file in below format. I trying to find a solution for finding percentage used for each of the NAMEs. Directory ALLOCATED USED NAME1 93MB 93KB NAME2 25G 62K NAME3 14G 873M NAME4 25G 62K NAME5 20G... (10 Replies)
Discussion started by: ctrld
10 Replies

3. Shell Programming and Scripting

Calculate Percentage

Hello, Ive got a bunch of numbers here e.g: 6065 6094 6348 6297 6161 6377 6338 6290 How do I find out if there is a difference between 10% or more between one of these numbers ? I am trying to do this in Bash.. but no luck so far.. Does anyone have an Idea ?? Thanx, - Pascal... (9 Replies)
Discussion started by: denbekker
9 Replies

4. Shell Programming and Scripting

Need to monitor OS in percentage

Hi, I am looking for generic commands / scripts that could run across platforms especially on HP Itanium boxes to give me % of free OS parameters For eg: Free Total Memory RAM : 20 % Free Total Swap Memory: 35% Free Total CPU utilisation: 44% Free Disk Space: /appl = 55%... (5 Replies)
Discussion started by: mohtashims
5 Replies

5. Shell Programming and Scripting

Percentage Calculation in Decimal

Hi, I have two variable and I need to calculate the percentage of them. Example: (b-a)*100/b How can I do it? I need to do it till 2 decimal point. (16 Replies)
Discussion started by: Anupam_Halder
16 Replies

6. Shell Programming and Scripting

awk/sed percentage calculation

Hi all i have a text file with columns delimited with , 2010-08-18,10,24,.09751,39,7,14872,26732 . . . i would to add a extra column in the end with percentage calculation of columns 5 and 8 ie (39/26732)*100 so the output must look like ... (6 Replies)
Discussion started by: posner
6 Replies

7. UNIX for Dummies Questions & Answers

percentage

How to calculate percentage of two values in unix. (5 Replies)
Discussion started by: venkatesht
5 Replies

8. Shell Programming and Scripting

How can i calculate percentage ??

i have 3 files like total.dat=18 equal.dat=14 notequal.dat=16 i need find the equal percentange means: equalpercentage = ($equal.dat / $total.dat * 100) How i can do this ? I tried some of the answers to calculate the percentage in this forums.but it couldn't worked.Some one please... (6 Replies)
Discussion started by: bobprabhu
6 Replies

9. Shell Programming and Scripting

awk percentage

how would you calculate percentage by per line? Given a column of 16 lines, grab each line and divide it by the sum of the entire column and multiply by 100? thanks ... (8 Replies)
Discussion started by: rockiefx
8 Replies

10. Shell Programming and Scripting

percentage by line

hi, I am new to awk.. and getting used to the scripts. I have a small data set 5 coulms.. 16 rows. 1) I am trying to remove the percentages of each line of colum 3..like first line divided the sum of colum 3 divided by 100 and print it out. removing hte percentages of each line I would really... (3 Replies)
Discussion started by: rockiefx
3 Replies
Login or Register to Ask a Question