- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ksh mutliply 0.2 constant with value and output
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
Discussions
Discussions
Forums
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
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
тАО08-14-2002 07:00 AM
тАО08-14-2002 07:00 AM
I want to mulitply a VALUE=100
with a CONSTANT=0.02 and display the results with decimal places.
If I try ...
(( NUM = 100 * 0.2 ))
printf "Answer is %4.2f\n" , $NUM
The result comes back as
Answer is 44.00
Answer is 0.00
Any ideas
Thanks
when I am want 20
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2002 07:10 AM
тАО08-14-2002 07:10 AM
Re: ksh mutliply 0.2 constant with value and output
NUM=`expr 100 \* 2 / 10`
printf "Answer is %4.2f\n" , $NUM
Hope this helps.
...jcd...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2002 07:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2002 07:17 AM
тАО08-14-2002 07:17 AM
Re: ksh mutliply 0.2 constant with value and output
ksh does integer arithmetic. 0.2 rounds to integer 0, so the multiplication produces 0.
Can you do
(( NUM = 100 * 2 / 10 ))
This will produce 20.
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2002 07:18 AM
тАО08-14-2002 07:18 AM
Re: ksh mutliply 0.2 constant with value and output
Try this simple awk command:
# echo | awk '{print 100 * 0.2}'
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2002 08:31 AM
тАО08-14-2002 08:31 AM
Re: ksh mutliply 0.2 constant with value and output
Robin is correct. You will need to use something like bc.
My above example, though produces the correct output for the example, will give an incorrect response in the event of a fraction.
...jcd...