<?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 How to calculate decimal number ? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-decimal-number/m-p/2481259#M776812</link>
    <description>If I run `expr 1 / 2` it will output 0.&lt;BR /&gt;How can I write a script to generate the result 0.5 ?&lt;BR /&gt;Thanks !</description>
    <pubDate>Wed, 10 Jan 2001 08:57:00 GMT</pubDate>
    <dc:creator>Patrick Chim</dc:creator>
    <dc:date>2001-01-10T08:57:00Z</dc:date>
    <item>
      <title>How to calculate decimal number ?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-decimal-number/m-p/2481259#M776812</link>
      <description>If I run `expr 1 / 2` it will output 0.&lt;BR /&gt;How can I write a script to generate the result 0.5 ?&lt;BR /&gt;Thanks !</description>
      <pubDate>Wed, 10 Jan 2001 08:57:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-decimal-number/m-p/2481259#M776812</guid>
      <dc:creator>Patrick Chim</dc:creator>
      <dc:date>2001-01-10T08:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate decimal number ?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-decimal-number/m-p/2481260#M776813</link>
      <description>You can try&lt;BR /&gt;&lt;BR /&gt;echo "scale=2 ; 1 / 2" | bc</description>
      <pubDate>Wed, 10 Jan 2001 09:13:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-decimal-number/m-p/2481260#M776813</guid>
      <dc:creator>Dave Kelly_1</dc:creator>
      <dc:date>2001-01-10T09:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate decimal number ?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-decimal-number/m-p/2481261#M776814</link>
      <description>I had the same problem. I just wrote a little C++ program (for multiplication):&lt;BR /&gt;&lt;BR /&gt;int main(int argc, char ** argv)&lt;BR /&gt;{&lt;BR /&gt;  cout &amp;lt;&amp;lt; atof(argv[1]) * atof(argv[2]) &amp;lt;&amp;lt; endl;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Then you can use this program in your script to calculate decimal numbers.</description>
      <pubDate>Wed, 10 Jan 2001 09:20:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-decimal-number/m-p/2481261#M776814</guid>
      <dc:creator>Thomas Kollig</dc:creator>
      <dc:date>2001-01-10T09:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate decimal number ?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-decimal-number/m-p/2481262#M776815</link>
      <description>Hi Patrick,&lt;BR /&gt;&lt;BR /&gt;'expr' won't give you anything but integers.&lt;BR /&gt;If you want nearly unlimited precision, you should use 'bc' like this:&lt;BR /&gt;echo "scale=2\n5/2" | bc&lt;BR /&gt;&lt;BR /&gt;Result will be 0.50 as expected.&lt;BR /&gt;Adjust the scale according to your needs.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;&lt;BR /&gt;Dan&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 10 Jan 2001 09:23:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-decimal-number/m-p/2481262#M776815</guid>
      <dc:creator>Dan Hetzel</dc:creator>
      <dc:date>2001-01-10T09:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate decimal number ?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-decimal-number/m-p/2481263#M776816</link>
      <description>Hi Patrick,&lt;BR /&gt;&lt;BR /&gt;If you have many operations to do in your script, you could use a two-way pipe to 'bc' instead of running bc many times.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;# This starts bc with a two-way pipe&lt;BR /&gt;bc |&amp;amp;&lt;BR /&gt;# print -p writes to the pipe&lt;BR /&gt;print -p scale=2&lt;BR /&gt;print -p 3/4&lt;BR /&gt;# read -p reads from the pipe&lt;BR /&gt;read -p myvar&lt;BR /&gt;echo $myvar&lt;BR /&gt;&lt;BR /&gt;The script here above will echo '.75'&lt;BR /&gt;&lt;BR /&gt;see manual for sh-posix&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;&lt;BR /&gt;Dan&lt;BR /&gt;</description>
      <pubDate>Wed, 10 Jan 2001 09:30:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-decimal-number/m-p/2481263#M776816</guid>
      <dc:creator>Dan Hetzel</dc:creator>
      <dc:date>2001-01-10T09:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate decimal number ?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-decimal-number/m-p/2481264#M776817</link>
      <description>you could use a shell that supports floating point arithmetic:&lt;BR /&gt;&lt;BR /&gt;#!/usr/dt/bin/dtksh&lt;BR /&gt;&lt;BR /&gt;float x&lt;BR /&gt;x=1.0/2  #one has to be floating point or it will perform integer arthimetic&lt;BR /&gt;print $x</description>
      <pubDate>Wed, 10 Jan 2001 16:17:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-decimal-number/m-p/2481264#M776817</guid>
      <dc:creator>Curtis Larson</dc:creator>
      <dc:date>2001-01-10T16:17:34Z</dc:date>
    </item>
  </channel>
</rss>

