<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: rounding numbers..my script function needs extension in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966021#M757698</link>
    <description>Hi,&lt;BR /&gt;so you want to round up to the nearest multiple of 5 ?&lt;BR /&gt;&lt;BR /&gt;a=`echo "$1/5"|bc`&lt;BR /&gt;b=`expr $a + 1`&lt;BR /&gt;c=`echo "$b*5"|bc`&lt;BR /&gt;&lt;BR /&gt;Input/output&lt;BR /&gt;4&lt;BR /&gt;a=0;b=1;c=5&lt;BR /&gt;5&lt;BR /&gt;a=1;b=2;c=10&lt;BR /&gt;&lt;BR /&gt;Please also read:&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/helptips.do?#33" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/helptips.do?#33&lt;/A&gt; on how to reward any useful answers given to your questions.&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 21 Mar 2007 09:46:52 GMT</pubDate>
    <dc:creator>Peter Godron</dc:creator>
    <dc:date>2007-03-21T09:46:52Z</dc:date>
    <item>
      <title>rounding numbers..my script function needs extension</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966018#M757695</link>
      <description>I made function in ksh:&lt;BR /&gt;&lt;BR /&gt;function  tarif&lt;BR /&gt;        {&lt;BR /&gt;                a=$1    &lt;BR /&gt;                TarifToolConst=$2               &lt;BR /&gt;                b=`echo "($a+4)/5" | bc`&lt;BR /&gt;                c=`echo "$b * 5" | bc`&lt;BR /&gt;&lt;BR /&gt;                #x=`echo "($a)/5" | bc`&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;                f=`echo "scale=3;($b * $TarifToolConst) / 100" | bc`&lt;BR /&gt;                g=`echo "(($b * $TarifToolConst) / 100)+1" | bc`&lt;BR /&gt;                d=`echo "scale=3;($c * $TarifToolConst) / 100" | bc`&lt;BR /&gt;                e=`echo "(($c * $TarifToolConst) / 100)+1" | bc`&lt;BR /&gt;                        echo "entry $a Rounded input $c Exit $d Rounded Exit $e and f is $f rounded price is $g USD"&lt;BR /&gt;                #a=`expr $a + 1`&lt;BR /&gt;        }&lt;BR /&gt;&lt;BR /&gt;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..&lt;BR /&gt;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..&lt;BR /&gt;&lt;BR /&gt;any help or hint is appreciated..&lt;BR /&gt;&lt;BR /&gt;Cheers,</description>
      <pubDate>Wed, 21 Mar 2007 09:14:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966018#M757695</guid>
      <dc:creator>amonamon</dc:creator>
      <dc:date>2007-03-21T09:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: rounding numbers..my script function needs extension</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966019#M757696</link>
      <description>You can do all of this in one bc command. It is extremely inefficient to invoke one-line commands in the shell to execute a simple bc command. Your problem is that your bias (4) should be 5 although in almost all cases when rounding to the nearest 5, if I enter 10 then I would expect 10 as an output.&lt;BR /&gt;&lt;BR /&gt;b=`echo "($a+4)/5" | bc`&lt;BR /&gt;c=`echo "$b * 5" | bc`&lt;BR /&gt;&lt;BR /&gt;can be:&lt;BR /&gt;&lt;BR /&gt;c=$(echo "((${a} + 5)/5) * 5")</description>
      <pubDate>Wed, 21 Mar 2007 09:41:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966019#M757696</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-03-21T09:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: rounding numbers..my script function needs extension</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966020#M757697</link>
      <description>nice hint..I love it..&lt;BR /&gt;I will change it!&lt;BR /&gt;But that is not releted to my problem..&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Mar 2007 09:45:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966020#M757697</guid>
      <dc:creator>amonamon</dc:creator>
      <dc:date>2007-03-21T09:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: rounding numbers..my script function needs extension</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966021#M757698</link>
      <description>Hi,&lt;BR /&gt;so you want to round up to the nearest multiple of 5 ?&lt;BR /&gt;&lt;BR /&gt;a=`echo "$1/5"|bc`&lt;BR /&gt;b=`expr $a + 1`&lt;BR /&gt;c=`echo "$b*5"|bc`&lt;BR /&gt;&lt;BR /&gt;Input/output&lt;BR /&gt;4&lt;BR /&gt;a=0;b=1;c=5&lt;BR /&gt;5&lt;BR /&gt;a=1;b=2;c=10&lt;BR /&gt;&lt;BR /&gt;Please also read:&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/helptips.do?#33" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/helptips.do?#33&lt;/A&gt; on how to reward any useful answers given to your questions.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Mar 2007 09:46:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966021#M757698</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2007-03-21T09:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: rounding numbers..my script function needs extension</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966022#M757699</link>
      <description>Note that I not only changed your two statements into one but I also increased the bias to 5 which should do the "rounding" exactly as you wanted.&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;((10 + 5)/5) * 5 = 15&lt;BR /&gt;((11 + 5)/5) * 5 = 15&lt;BR /&gt;((14 + 5)/5) * 5 = 15&lt;BR /&gt;&lt;BR /&gt;Note that if you are doing interger math then you don't even need bc; you can do it in the shell.</description>
      <pubDate>Wed, 21 Mar 2007 09:53:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966022#M757699</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-03-21T09:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: rounding numbers..my script function needs extension</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966023#M757700</link>
      <description>&amp;gt;I want if as input to this function I enter 10 this should be rounded to 15&lt;BR /&gt;&lt;BR /&gt;Didn't I already show something similar in your previous post:&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1100461" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1100461&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Clay: I also increased the bias to 5 which should do the "rounding" exactly as you wanted.&lt;BR /&gt;&lt;BR /&gt;You could also truncate then add 1:&lt;BR /&gt;   (( c = (a/5 + 1) * 5 ))&lt;BR /&gt;&lt;BR /&gt;I'm not sure what you intended by this:&lt;BR /&gt;c=$(echo "((${a} + 5)/5) * 5")&lt;BR /&gt;&lt;BR /&gt;That "*" is getting globbed.</description>
      <pubDate>Thu, 22 Mar 2007 02:03:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966023#M757700</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-03-22T02:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: rounding numbers..my script function needs extension</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966024#M757701</link>
      <description>&amp;gt;I'm not sure what you intended by this:&lt;BR /&gt;c=$(echo "((${a} + 5)/5) * 5")&lt;BR /&gt;&lt;BR /&gt;Perhaps you wanted this?&lt;BR /&gt;c=$(( (a + 5)/5 * 5 ))  # spaces not needed</description>
      <pubDate>Thu, 22 Mar 2007 02:09:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966024#M757701</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-03-22T02:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: rounding numbers..my script function needs extension</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966025#M757702</link>
      <description>thanks a lot guys</description>
      <pubDate>Thu, 22 Mar 2007 02:12:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rounding-numbers-my-script-function-needs-extension/m-p/3966025#M757702</guid>
      <dc:creator>amonamon</dc:creator>
      <dc:date>2007-03-22T02:12:21Z</dc:date>
    </item>
  </channel>
</rss>

