<?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: decimals in shell script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507203#M21652</link>
    <description>if you use a more intelligent shell:&lt;BR /&gt;&lt;BR /&gt;#!/usr/dt/bin/dtksh&lt;BR /&gt;&lt;BR /&gt;var=5.6&lt;BR /&gt;print $(( var=int($var) ))&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 20 Mar 2001 15:08:54 GMT</pubDate>
    <dc:creator>Curtis Larson</dc:creator>
    <dc:date>2001-03-20T15:08:54Z</dc:date>
    <item>
      <title>decimals in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507196#M21645</link>
      <description>Would someone know how to remove the decimal from a decimal number?&lt;BR /&gt;&lt;BR /&gt;ex) &lt;BR /&gt;&lt;BR /&gt;var=5.6&lt;BR /&gt;echo $var  (only want 5 to show)&lt;BR /&gt;&lt;BR /&gt;Thanks, &lt;BR /&gt;Tony</description>
      <pubDate>Tue, 20 Mar 2001 14:30:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507196#M21645</guid>
      <dc:creator>Tony  LeBlanc</dc:creator>
      <dc:date>2001-03-20T14:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: decimals in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507197#M21646</link>
      <description>Hi Tony:&lt;BR /&gt;&lt;BR /&gt;One way is to use 'awk' with the "." as the field delimiter:&lt;BR /&gt;&lt;BR /&gt;# V=5.6&lt;BR /&gt;# echo $V|awk -F. '{print $1}'&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 20 Mar 2001 14:52:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507197#M21646</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-03-20T14:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: decimals in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507198#M21647</link>
      <description>#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;integer i&lt;BR /&gt;&lt;BR /&gt;var=5.6&lt;BR /&gt;i=$var&lt;BR /&gt;echo $i</description>
      <pubDate>Tue, 20 Mar 2001 14:52:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507198#M21647</guid>
      <dc:creator>Curtis Larson</dc:creator>
      <dc:date>2001-03-20T14:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: decimals in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507199#M21648</link>
      <description>Tony,&lt;BR /&gt;&lt;BR /&gt;With printf;&lt;BR /&gt;&lt;BR /&gt;printf "%5.0f" $var&lt;BR /&gt;&lt;BR /&gt;Greetz, Danny</description>
      <pubDate>Tue, 20 Mar 2001 14:55:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507199#M21648</guid>
      <dc:creator>Danny Engelbarts</dc:creator>
      <dc:date>2001-03-20T14:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: decimals in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507200#M21649</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;just another way:&lt;BR /&gt;&lt;BR /&gt;val=5.6&lt;BR /&gt;echo ${val%.*}&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Tue, 20 Mar 2001 14:57:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507200#M21649</guid>
      <dc:creator>Andreas Voss</dc:creator>
      <dc:date>2001-03-20T14:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: decimals in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507201#M21650</link>
      <description>The Korn or Posix shell's integer arithmetic facility is probably the most elegant solution.&lt;BR /&gt;&lt;BR /&gt;Provided the value supplied is a valid number&lt;BR /&gt; (the shell will print a failure message to standard error if it isn't) then&lt;BR /&gt;&lt;BR /&gt;let VAR=&lt;VALUE&gt;&lt;BR /&gt;print ${VAR}&lt;BR /&gt;&lt;BR /&gt;will do the trick. The let command implies 'integer VAR' which is an alias to 'typeset -i VAR'&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;John&lt;/VALUE&gt;</description>
      <pubDate>Tue, 20 Mar 2001 15:00:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507201#M21650</guid>
      <dc:creator>John Palmer</dc:creator>
      <dc:date>2001-03-20T15:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: decimals in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507202#M21651</link>
      <description>Tony:&lt;BR /&gt;&lt;BR /&gt;...and here's yet another:&lt;BR /&gt;&lt;BR /&gt;# V=5.6&lt;BR /&gt;# echo "$V / 1"|bc&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 20 Mar 2001 15:07:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507202#M21651</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-03-20T15:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: decimals in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507203#M21652</link>
      <description>if you use a more intelligent shell:&lt;BR /&gt;&lt;BR /&gt;#!/usr/dt/bin/dtksh&lt;BR /&gt;&lt;BR /&gt;var=5.6&lt;BR /&gt;print $(( var=int($var) ))&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 20 Mar 2001 15:08:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507203#M21652</guid>
      <dc:creator>Curtis Larson</dc:creator>
      <dc:date>2001-03-20T15:08:54Z</dc:date>
    </item>
    <item>
      <title>Re: decimals in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507204#M21653</link>
      <description>Well,  Since people were posting some of the alternate ways of doing this.   I decided to have some fun.  I wrote this one out of pure boredom.   &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;#----------------------------------------------------------&lt;BR /&gt;# Script Written by: Brian Markus - bmarkus@rcoe.k12.ca.us &lt;BR /&gt;# Reason - pure boredom, and to help a fellow hpux'er&lt;BR /&gt;# This script will take any size decimal &lt;BR /&gt;# number assign the left side of the &lt;BR /&gt;# decimal to a variable named predec,&lt;BR /&gt;# then assign the right side of the decimal&lt;BR /&gt;# to a variable named postdec&lt;BR /&gt;#----------------------------------------------------------&lt;BR /&gt;# Set your variable with the decimal&lt;BR /&gt;# assign the the decimal number to decnum&lt;BR /&gt;decnum=549890.398&lt;BR /&gt;&lt;BR /&gt;#display your variable before altering it&lt;BR /&gt;echo "pre number = $decnum" &lt;BR /&gt;&lt;BR /&gt;#get the length of the variable&lt;BR /&gt;varlen=`expr length $decnum`&lt;BR /&gt;&lt;BR /&gt;#find the position that the decimal is in&lt;BR /&gt;decpos=`expr index $decnum \.`&lt;BR /&gt;&lt;BR /&gt;#set the end point for the left side of the decimal&lt;BR /&gt;let decpos=decpos-1&lt;BR /&gt;&lt;BR /&gt;#assign the left side of the decimal to predec&lt;BR /&gt;predec=`expr substr $decnum 1 $decpos`&lt;BR /&gt;&lt;BR /&gt;#set the beginning point on the right side of the decimal &lt;BR /&gt;let decpos=decpos+2&lt;BR /&gt;&lt;BR /&gt;#assign the right side of the decimal to postdec&lt;BR /&gt;postdec=`expr substr $decnum $decpos $varlen`&lt;BR /&gt;&lt;BR /&gt;#put the left and right side together with out the decimal&lt;BR /&gt;newnumber=${predec}${postdec}&lt;BR /&gt;&lt;BR /&gt;#display the new built number&lt;BR /&gt;echo "post number = $newnumber"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;hope this helps&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Brian.</description>
      <pubDate>Tue, 20 Mar 2001 20:25:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507204#M21653</guid>
      <dc:creator>Brian Markus</dc:creator>
      <dc:date>2001-03-20T20:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: decimals in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507205#M21654</link>
      <description>If you want to truncate the numbers after the decimal, you could just use the $predec  var.  and not process the rest.   I got carried away.  It's always best to follow the KISS rule.  Everyone's posted a good solution.  This method is a bit more advanced and cumbersome, but it's easy to follow.</description>
      <pubDate>Tue, 20 Mar 2001 20:31:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/decimals-in-shell-script/m-p/2507205#M21654</guid>
      <dc:creator>Brian Markus</dc:creator>
      <dc:date>2001-03-20T20:31:19Z</dc:date>
    </item>
  </channel>
</rss>

