<?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: calculating variables with decimals in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/calculating-variables-with-decimals/m-p/4824445#M641636</link>
    <description>&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In addition to using 'bc', 'awk' or Perl as Hein has advised, you could leverage the 'dtksh' shell in lieu of the 'ksh' one.&amp;nbsp; The 'dtksh' shell is a Korn93 variant whereas the 'ksh' one of HP-UX is Korn88.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can find 'dtksh' as '/usr/dt/bin/dtksh' (which requires installlation of the CDE bundle on 11.31).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;# cat ./mycalc
#!/usrb/dt/bin/dtksh
typeset -E MSZ
typeset -E SZ=.5
MSZ=$((SZ*1024))
echo ${MSG}
exit 0&lt;/PRE&gt;&lt;P&gt;# ./mycalc&lt;/P&gt;&lt;P&gt;512&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...JRF...&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jul 2011 12:57:16 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2011-07-13T12:57:16Z</dc:date>
    <item>
      <title>calculating variables with decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calculating-variables-with-decimals/m-p/4824241#M641634</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in ksh scripting can someone tell me how to calculate decimal numbers ie:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sz=0.5&lt;/P&gt;&lt;P&gt;msz=$(($sz*1024))&lt;/P&gt;&lt;P&gt;echo $msz&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know printf will help me out but not sure of the syntax&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2011 09:49:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calculating-variables-with-decimals/m-p/4824241#M641634</guid>
      <dc:creator>lawrenzo</dc:creator>
      <dc:date>2011-07-13T09:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: calculating variables with decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calculating-variables-with-decimals/m-p/4824397#M641635</link>
      <description>&lt;P&gt;SOL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Shells typically deal with integer only.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can &amp;nbsp;store the decimal values a piece of string, but the math will be integer.&lt;/P&gt;&lt;P&gt;You will have to reach out to a tool like 'bc' to do the floating point math.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suspect that the script you are working with is more about parsing and juggling numbers and string&lt;/P&gt;&lt;P&gt;than it is about&amp;nbsp;issuing&amp;nbsp;commands&lt;/P&gt;&lt;P&gt;If so, then personally I would just step into AWK or PERL and do all of those chunks of script there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;&lt;P&gt;Hein&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2011 12:20:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calculating-variables-with-decimals/m-p/4824397#M641635</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2011-07-13T12:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: calculating variables with decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calculating-variables-with-decimals/m-p/4824445#M641636</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In addition to using 'bc', 'awk' or Perl as Hein has advised, you could leverage the 'dtksh' shell in lieu of the 'ksh' one.&amp;nbsp; The 'dtksh' shell is a Korn93 variant whereas the 'ksh' one of HP-UX is Korn88.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can find 'dtksh' as '/usr/dt/bin/dtksh' (which requires installlation of the CDE bundle on 11.31).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;# cat ./mycalc
#!/usrb/dt/bin/dtksh
typeset -E MSZ
typeset -E SZ=.5
MSZ=$((SZ*1024))
echo ${MSG}
exit 0&lt;/PRE&gt;&lt;P&gt;# ./mycalc&lt;/P&gt;&lt;P&gt;512&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...JRF...&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2011 12:57:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calculating-variables-with-decimals/m-p/4824445#M641636</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-07-13T12:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: calculating variables with decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calculating-variables-with-decimals/m-p/4824511#M641637</link>
      <description>&lt;P&gt;in ksh you can also do fix point calculation , if you don"t deal with too small or too large numbers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For instance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to calculate all with 2 decimal digits.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# sz=50&lt;BR /&gt;# msz=$(($sz*1024))&lt;BR /&gt;# printf "%d.%02d\n" $((msz/100)) $((msz%100))&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;512.00&lt;BR /&gt;﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(10.24 + 11.35)*2.35&lt;/P&gt;&lt;P&gt;you do&lt;/P&gt;&lt;P&gt;typeset&amp;nbsp; -i res&lt;/P&gt;&lt;P&gt;res=$(((1024*1035)*235))﻿&lt;/P&gt;&lt;P&gt;# printf "%d.%04d\n" $((res/10000)) $((res%10000))&lt;/P&gt;&lt;P&gt;24906.2400&lt;BR /&gt;﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&amp;nbsp;&lt;P&gt;﻿&lt;/P&gt;&lt;P&gt;﻿&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2011 13:29:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calculating-variables-with-decimals/m-p/4824511#M641637</guid>
      <dc:creator>Laurent Menase</dc:creator>
      <dc:date>2011-07-13T13:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: calculating variables with decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calculating-variables-with-decimals/m-p/4824647#M641638</link>
      <description>&lt;P&gt;ok great thanks for the info everyone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2011 14:30:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calculating-variables-with-decimals/m-p/4824647#M641638</guid>
      <dc:creator>lawrenzo</dc:creator>
      <dc:date>2011-07-13T14:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: calculating variables with decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calculating-variables-with-decimals/m-p/4824993#M641639</link>
      <description>&lt;P&gt;&amp;gt;in ksh you can also do fix point calculation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, exactly what COBOL does automatically.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2011 16:47:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calculating-variables-with-decimals/m-p/4824993#M641639</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-07-13T16:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: calculating variables with decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calculating-variables-with-decimals/m-p/4827981#M641640</link>
      <description>&lt;P&gt;&amp;gt;&amp;gt;in ksh you can also do fix point calculation﻿&lt;/P&gt;&lt;P&gt;&amp;gt;Yes, exactly what COBOL does automatically.﻿&lt;/P&gt;&lt;P&gt;Or old assembly uses when floating point coproc was not so common.&lt;/P&gt;&lt;P&gt;In most case it is enough in scripts, keeping an implicit exponent, it is just basic arithmetic&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 15 Jul 2011 12:24:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calculating-variables-with-decimals/m-p/4827981#M641640</guid>
      <dc:creator>Laurent Menase</dc:creator>
      <dc:date>2011-07-15T12:24:07Z</dc:date>
    </item>
  </channel>
</rss>

