- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Calculation in Ksh !
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
07-17-2003 08:02 AM
07-17-2003 08:02 AM
I am just wondering whether I can do decimal calculation in Ksh environment !!
I have tried to calcuate 10/100 in Ksh and the result will be integer 0
Can I create and control the number of decimal point e.g. 0.1 or 0.10 for the above calcuation ??
Many thanks
Chris,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2003 08:06 AM
07-17-2003 08:06 AM
Re: Calculation in Ksh !
A Forums search will reveal many different approaches.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2003 08:16 AM
07-17-2003 08:16 AM
Re: Calculation in Ksh !
Using 'bc' is easy and offers a choice of the input and output base, scale and length of output. For instance:
# X=`echo "ibase=16;F+F;obase=10"|bc`;echo ${X}
# Y=`echo "scale=3;1/8"|bc`;echo ${Y}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2003 09:14 AM
07-17-2003 09:14 AM
Re: Calculation in Ksh !
Though it would be best to get used to using the utilities previously mentioned, in a down and dirty, simply multiply by 100.
I have done this quite often in simple scripts then set the decimal point to get percentages, etc.
Best of luck.
Regards,
dl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2003 09:28 AM
07-17-2003 09:28 AM
Re: Calculation in Ksh !
but /usr/dt/bin/dtksh does include most of the 93 version of the korn shell features including floating point arithmetic. So you
can do something like this if you like.
#!/usr/dt/bin/dtksh
typeset -F a=3 b=4 c # specify the floating point attribute
c=$(( $a/$b ))
print $c
#or
printf "%4.3f\n" $(( $a/$b ))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2003 09:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2003 10:19 AM
07-17-2003 10:19 AM