473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

How do I get percentage output from a csh script?

I am writing a csh script and trying to get percentage output figures. When I divide two figures all I get is a zero value instead of the percentage number I'm looking for. Thanks.
Nov 18 '09 #1

✓ answered by RRick

The simple answer is that you can't get percentages directly from csh. What you need is a scripting language that handles doubles or floats and most of the unix shell languages don't.

There is a special command line calculator (bc) that will work with floating values. It takes simple string commands and spits out the value. For example:
$ echo "40./57." | bc -l
.70175438596491228070
You can fake percentages in csh by using integers instead. Instead of dividing B by A, first multiply B by 100 and divide by A. The integer answer will be the percent value. If you want to have the answer rounded to the nearest percent, try RoundUp=(B*1000+A*5)/A*10.

If this is too painful, try a scripting language that supports doubles. Perl is one.

1 4747
RRick
463 Expert 256MB
The simple answer is that you can't get percentages directly from csh. What you need is a scripting language that handles doubles or floats and most of the unix shell languages don't.

There is a special command line calculator (bc) that will work with floating values. It takes simple string commands and spits out the value. For example:
$ echo "40./57." | bc -l
.70175438596491228070
You can fake percentages in csh by using integers instead. Instead of dividing B by A, first multiply B by 100 and divide by A. The integer answer will be the percent value. If you want to have the answer rounded to the nearest percent, try RoundUp=(B*1000+A*5)/A*10.

If this is too painful, try a scripting language that supports doubles. Perl is one.
Nov 19 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Put 030516 in email subj to get thru | last post by:
I've always been bothered about having to statically declare the size of a Java applet window (container?) in the calling HTML. I've always wanted the moral equivalent of width=50% statement (of...
6
by: Bruce Eckel | last post by:
Background: for the 4th edition of Thinking in Java, I'm trying to once again improve the testing scheme for the examples in the book. I want to verify that the output I show in the book is...
1
by: Steve | last post by:
Hi; Before I start let me say I know this is a silly way to go about things, but it is one of those "my company made me do it" things. My company is in the process of ( finishing ) migrating...
1
by: Don Leverton | last post by:
Hi Folks, I *can* calculate the Gross Profit Percentage where both the Cost and SellPrice are known, using the formula: (SellPrice - Cost) / SellPrice = GPP eg ($24.92 - $14.95) / $24.92 =...
0
by: fake ID | last post by:
Since you can't search for these symbols used in asp.net "<%#" or '<%=' I thought i'd post this to make things a little easier to find. Potential search word combinations: -lessthan Percentage...
4
by: thisis | last post by:
Hi All, i'm trying to display the amout in percentage for the loading sub event value, for the <img .../> example: the browser should display something like this:
1
by: grannyguest | last post by:
Hi, My name is Linda. I am retrieving a field defined in SQL Server as Number 5(5,3). I need to convert that field to a percentage number but I do not want the % sign. For example if the field...
39
by: Umesh | last post by:
Plese help. Is there any software by which we can do that?
5
by: Aswanth | last post by:
I'm Using Asp.Net with C# & Working with SSRS 2005 for Generating Reports.. The Following Expression I'm using in Reports to Show the Percentage of Particular Items in REPORT.. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.