- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- shell script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2000 11:10 PM
04-12-2000 11:10 PM
shell script
let a=50/100
echo $a
output is 0
how do I get a 0.50 output?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2000 02:45 AM
04-13-2000 02:45 AM
Re: shell script
a=`echo "scale=2 ; 50 / 100" | bc`
echo $a
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2000 07:44 AM
05-26-2000 07:44 AM
Re: shell script
try formated output with
printf "%5.2f" $a
see man printf for detailed information
best regards
Klaus Frank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2000 03:43 AM
05-31-2000 03:43 AM
Re: shell script
Try the following:
X=$(print|awk '{printf("%.2fn",50/100)}')
This may look ugly, but the awk command is capable of processing floating-point numbers.
Details of the command:
$() - execute the shell commands within
awk - awk command
print - pass awk blank line
printf - formatted print command
%.2f - real number 2 places past decimal
n - newline
Brian
<*(((>< er
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2000 04:55 AM
05-31-2000 04:55 AM
Re: shell script
It is possible, though a bit complicated, to do it all in Shell (Posix/Korn, but may work in Bourne too) using a function. I wrote such a function (called fdiv), put in the attachment. For example:
$ fdiv 3 7 3
0.428
(the 3rd parameter is the number of digits).
Hope it helps,
Emmanuel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2000 08:53 AM
07-14-2000 08:53 AM
Re: shell script
#! /usr/dt/bin/dtksh
float a # float is usually aliased to typeset -E
(( a = 50/100 ))
printf "%fn" $a
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2000 09:04 AM
07-14-2000 09:04 AM
Re: shell script
printf "fn" $a
of course the printf supports the usual C syntax of:
%[flags][field_width][precision][base]conversion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2000 09:17 AM
07-14-2000 09:17 AM
Re: shell script
printf "(percent)f(backslash)n" $a
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2000 10:10 AM
07-14-2000 10:10 AM
Re: shell script
It is a thing with the forum postin, for front slash to appear, you have to make it double too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2000 07:09 AM
07-15-2000 07:09 AM
Re: shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2000 09:08 AM
07-27-2000 09:08 AM
Re: shell script
# Set scale = # of decimal places you want
NUMBER="10/5" # Your formula
ANSWER=`bc -l <<-EOF
scale = 2
${NUMBER}
EOF`
This should work for you, but the value in ANSWER is text, not number since shell can
only handle integer values.