Script to provide percentages?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to provide percentages?
# 1  
Old 02-26-2012
Script to provide percentages?

so i'm have been stifled here inn my attempts at this.

i need to calculate an unusual figure.

what is the percentage difference between 400 and 3?

usually, to get the percentage, you just divide the smaller number by the bigger number. then multiply the answer by 100.

in this case however, 3 divided 400 gives a 0.0075. that means nothing to me. how can i get the real percentage of this?
# 2  
Old 02-26-2012
Code:
$ printf "%0.2f\%\n"  $(( 100 * (3.00/400)))
0.75%

This User Gave Thanks to fpmurphy For This Post:
# 3  
Old 02-26-2012
Quote:
Originally Posted by fpmurphy
Code:
$ printf "%0.2f\%\n"  $(( 100 * (3.00/400)))
0.75%


this actually might work but i'm not exactly sure if its 100% correct. let me see if i can explain this in a different way.

if you made $400 yesterday, and made $3 tomorrow. that is huge difference. what is the percentage of that difference? its way more than 75%. it near the 300% range. my question is, how can we get the exact percentage...even though it will be over 100?
# 4  
Old 02-26-2012
This sounds more like a question to a math forum!
However, the percentage calculation depends on what you take as the reference.
Code:
echo "scale=5; 3/400*100" | bc
.75000

echo "scale=5; 400/3*100" | bc
13333.33300

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 5  
Old 02-27-2012
Are you referring to the "Relative Difference"??

Calculation for relative difference is ((400/3)-1)*100
# 6  
Old 02-27-2012
Quote:
Originally Posted by fpmurphy
Code:
$ printf "%0.2f\%\n"  $(( 100 * (3.00/400)))
0.75%

Quote:
Originally Posted by SkySmart
its way more than 75%
1. Solution provided by fpmurphy is the answer to question "What percentage of my yesterday's income is today's income?" And it's 0.75%, not 75%.

2. If you made $400 yesterday and $3 today, there's a reduction in 99.25% of your income -> (((400-3)/400)*100)

3. And looking at it the other way, you made 13233.33% more yesterday than the amount you made today -> (((400-3)/3)*100) Usually you don't get paid $3 the next day after you've been paid $400, so you don't get to see a figure like 13233% increase or 99.25% decrease !!

By the way, how is this related to 'Shell Programming and Scripting' forum?
This User Gave Thanks to balajesuri For This Post:
# 7  
Old 02-27-2012
Similar to balajesuri (option 2)

Mathematically shouldn't the answer be negative?:
Code:
echo "scale=2;(((3 - 400) * 100)/400)"|bc
-99.25 %


Last edited by methyl; 02-27-2012 at 08:57 AM.. Reason: units
This User Gave Thanks to methyl For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

How to provide password for rsync in shell script?

Hi, i want to call the rsync in a shell script so that i can run it in background by passing the password within script itself. Can any one please let me know how can i provide the password in the shell script itself so that rsync will read the password when promted by the script. Its very... (11 Replies)
Discussion started by: Little
11 Replies

2. Shell Programming and Scripting

Can any one provide shell script for this ...

• With this script, users will be able to o Enter into the recycle bin mode. During this mode, all files deleted will be sent to the recycle bin. The recycle bin will be common to all users. o View contents of the recycle bin (his/her file(s) only). o Retrieve a particular file from the recycle... (3 Replies)
Discussion started by: bhavana busetty
3 Replies

3. Shell Programming and Scripting

How to provide auto inputs for a sub-script within a script?

Hi All, I am writing a shell script. #!/bin/bash cat /etc/hosts mkdir -p /var/tmp mount 113.123.35.37:/vol/vol615/syb /var/tmp In above script I am trying to add below predefined script/command (/var/tmp/db_tools) This command in turn ask for user input, which will be always option... (17 Replies)
Discussion started by: madhur.baharani
17 Replies

4. Shell Programming and Scripting

Provide Password using to the application using the shell script

Hello, I have a requirement to shut down and start up my application on different environments (Dev, QA and Prod). I have around 24 servers. I have to login to each server manually for shutinng down the application. I wrote a shell command on each server and I am invoking those shell... (2 Replies)
Discussion started by: GDSR Raju
2 Replies

5. Shell Programming and Scripting

How the user will provide the parameters for Oracle db connection in a shell script?

I'm new into unix. My question: is possible to write a shell script which will ask for the ORACLE_HOME, ORACLE_SID, USERNAME, PASSWORD to connect to Oracle db. In generally we have to set the ORACLE_HOME in .profile file. And after putting the 'sqlplus' command it asks for the username &... (6 Replies)
Discussion started by: priya001
6 Replies

6. Shell Programming and Scripting

Writing a UNIX script from LOG to provide return code.

Folks - Firstly, I do apologize that my first post here is a question. I am quite familiar with UNIX since our application is running on it. We are trying to automate a few things on our end and I am challenged with a task in hand that requires UNIX scripting. I am totally a newbie in UNIX... (4 Replies)
Discussion started by: sk72
4 Replies

7. Shell Programming and Scripting

Please provide me with a KSH script.

Hi frnds Im new to unix. I have an xml like the following: <?xml version="1.0"?> <serviceFeeDetail> <Data> <totalAmount>40</totalAmount> </Data> <serviceFee> <invoiceBillGrpNbr>1</invoiceBillGrpNbr> <serviceFeeLineItem> <billLineNbr>1</billLineNbr> ... (2 Replies)
Discussion started by: balesh
2 Replies

8. Shell Programming and Scripting

Provide input in sqlplus script

Hi guys. I m creating scripts which input multiple value , inside sqlplus script when it prompt/accept do anybody know how to provide multiple value inside sqlplus script when it prompt. like, enter value for first: enter value for second: enter value "save file as " : I m try... (11 Replies)
Discussion started by: tapia
11 Replies

9. Shell Programming and Scripting

provide a user password from a script

Hi all, passwd <username> < /var/adm/passwd.txt cat /var/adm/passwd.txt abcd1234 abcd1234 when I run this from the script, it comes with: New password: It is not able to pick from the location /var/adm/passwd.txt. thanks in advance. (6 Replies)
Discussion started by: solaix14
6 Replies

10. Shell Programming and Scripting

ksh script using expr to calculate percentages

Within a ksh script on HP-UX I trying to calculate a percentage of a number (number/100 x percentage) using the below method and expr. TARPERC=`expr 16 / 100 \* 5` TARSUM=`expr 16 + $TARPERC` ZIPSUM=`expr $TARSUM \* 2` If the input is 16 outputs are: TARPERC: 0 TARSUM: 16 ZIPSUM: 32... (6 Replies)
Discussion started by: wurzul
6 Replies
Login or Register to Ask a Question