- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- rounding numbers..my script function needs extensi...
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
03-21-2007 02:14 AM
03-21-2007 02:14 AM
function tarif
{
a=$1
TarifToolConst=$2
b=`echo "($a+4)/5" | bc`
c=`echo "$b * 5" | bc`
#x=`echo "($a)/5" | bc`
f=`echo "scale=3;($b * $TarifToolConst) / 100" | bc`
g=`echo "(($b * $TarifToolConst) / 100)+1" | bc`
d=`echo "scale=3;($c * $TarifToolConst) / 100" | bc`
e=`echo "(($c * $TarifToolConst) / 100)+1" | bc`
echo "entry $a Rounded input $c Exit $d Rounded Exit $e and f is $f rounded price is $g USD"
#a=`expr $a + 1`
}
but I want if as input to this function I enter 10 this should be rounded to 15..in my example it is rounded to 10..and if I enter 15 it should be rounded to 20 if 20 should be rouned to 25..is this possible I have no idea..
In my script it already rounds input if I enter 4 to 5 if I enter 11 to 15 if I enter 16 to 20 ..etc..
any help or hint is appreciated..
Cheers,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2007 02:41 AM
03-21-2007 02:41 AM
Re: rounding numbers..my script function needs extension
b=`echo "($a+4)/5" | bc`
c=`echo "$b * 5" | bc`
can be:
c=$(echo "((${a} + 5)/5) * 5")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2007 02:45 AM
03-21-2007 02:45 AM
Re: rounding numbers..my script function needs extension
I will change it!
But that is not releted to my problem..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2007 02:46 AM
03-21-2007 02:46 AM
Solutionso you want to round up to the nearest multiple of 5 ?
a=`echo "$1/5"|bc`
b=`expr $a + 1`
c=`echo "$b*5"|bc`
Input/output
4
a=0;b=1;c=5
5
a=1;b=2;c=10
Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2007 02:53 AM
03-21-2007 02:53 AM
Re: rounding numbers..my script function needs extension
e.g.
((10 + 5)/5) * 5 = 15
((11 + 5)/5) * 5 = 15
((14 + 5)/5) * 5 = 15
Note that if you are doing interger math then you don't even need bc; you can do it in the shell.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2007 07:03 PM
03-21-2007 07:03 PM
Re: rounding numbers..my script function needs extension
Didn't I already show something similar in your previous post:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1100461
>Clay: I also increased the bias to 5 which should do the "rounding" exactly as you wanted.
You could also truncate then add 1:
(( c = (a/5 + 1) * 5 ))
I'm not sure what you intended by this:
c=$(echo "((${a} + 5)/5) * 5")
That "*" is getting globbed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2007 07:09 PM
03-21-2007 07:09 PM
Re: rounding numbers..my script function needs extension
c=$(echo "((${a} + 5)/5) * 5")
Perhaps you wanted this?
c=$(( (a + 5)/5 * 5 )) # spaces not needed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2007 07:12 PM
03-21-2007 07:12 PM