- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- rounding up numbers...
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
02-14-2007 06:24 PM
02-14-2007 06:24 PM
Let say I have as input 13 in script it should be rounded to 15 and multiplied with 9.5 and divided with 100
(or if I have as input 11 it should return 15, or for 19 it should be 20)
result is 1,425 but becouse I want this to be rounded final result should be 2.
can anyone give me a clue or help me with this..I tried something in KSH with
line this:
$echo "scale=2; 13 / 100" | bc
thanks in advance..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2007 07:14 PM
02-14-2007 07:14 PM
Re: rounding up numbers...
could you please provide a few more expected output values, given these input values:
0
4
5
6
9
10
11=15
14
15
16
19=20
20
21
If I understand correctly, round to the nearest multiple of 5 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2007 07:20 PM
02-14-2007 07:20 PM
Re: rounding up numbers...
0 =0
4 =5
5 =5
6 =10
9 =10
10=10
11=15
14=15
15=15
16=20
19=20
20=20
21=25
first round in input..and it is rounded as above..
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2007 07:35 PM
02-14-2007 07:35 PM
Re: rounding up numbers...
how about:
#!/usr/bin/sh
a=0
while [ a -lt 30 ]
do
b=`echo "($a+4)/5" | bc`
c=`echo "$b * 5" | bc`
echo $a $b $c
a=`expr $a + 1`
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2007 08:38 PM
02-14-2007 08:38 PM
Re: rounding up numbers...
like this:
Let say I have as input 13 in script it should be rounded to 15 and then multiplied with 9.5(constant) and then divided with 100
(or if I have as input 11 it should return 15, or for 19 it should be 20)
result is 1,425 but becouse I want this to be rounded final result should be 2.
thansks for useful hint!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2007 09:45 PM
02-14-2007 09:45 PM
Solutionso, for
Input 13
Round up 13 to 15, then multiply 15 by 9.5 and devide by 100, resulting in 1.425. Then round this up to 2 ?
Can you please comment on results of:
#!/usr/bin/sh
a=0
while [ a -lt 30 ]
do
b=`echo "($a+4)/5" | bc`
c=`echo "$b * 5" | bc`
d=`echo "scale=3;($c * 9.5) / 100" | bc`
e=`echo "(($c * 9.5) / 100)+1" | bc`
echo "Input $a Rounded Input $c Output $d Rounded Output $e"
a=`expr $a + 1`
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2007 10:11 PM
02-14-2007 10:11 PM
Re: rounding up numbers...
thanks..:)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2007 03:47 PM
02-15-2007 03:47 PM
Re: rounding up numbers...
typeset -i a=0
while [ a -lt 30 ]; do
(( b = ((a+4)/5)*5 ))
echo "Input $a, Rounded Input $b"
(( a = a + 1 ))
done
If you want to change the number 5 above, that 4 is really (5-1).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2007 06:05 PM
02-15-2007 06:05 PM
Re: rounding up numbers...
Cheers,