- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Decimal add 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
08-07-2001 11:20 AM
08-07-2001 11:20 AM
let TOTAL=$(($TOTAL + $CPU))
and then; TOTAL variable return integer result whitout decimal.
any ideas ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2001 11:42 AM
08-07-2001 11:42 AM
Re: Decimal add in ksh
How about something like this:
#!/usr/bin/ksh
trunc()
{
printf "%.0f\n" $1
return 0
}
A=12.56
B=4.2
echo "A=${A}"
echo "B=${B}"
A=`trunc ${A}`
B=`trunc ${B}`
TOT=$((${A} + ${B}))
echo "TOT = ${TOT}"
exit 0
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2001 11:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2001 11:57 AM
08-07-2001 11:57 AM
Re: Decimal add in ksh
A + B=16.76
How can i view this result?
regards
MDF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2001 12:07 PM
08-07-2001 12:07 PM
Re: Decimal add in ksh
Sorry, in the first example, I forgot the 'echo'. It should read:
# TOTAL=`echo $TOTAL $CPU|awk '{print $1 + $2}'`
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2001 12:13 PM
08-07-2001 12:13 PM
Re: Decimal add in ksh
A=12.56
B=4.67
TOT=`echo "${A} ${B}" | awk '{printf("%.2f\n",$1,$2)}'`
That should do the floating point total rounded to 2 decimal places. You can change the printf format to any desired precision.
Clay
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2001 07:22 AM
08-08-2001 07:22 AM
Re: Decimal add in ksh
U can try this
TOTAL = `echo "$TOTAL + $CPU" | bc -l `
This should return TOTAL in Decimal
Sundar