<?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: bc doesnt do maths in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310206#M62728</link>
    <description>If your error is:&lt;BR /&gt;&lt;BR /&gt;line 12: [: 61.29032258064516129000: integer expression expected&lt;BR /&gt;&lt;BR /&gt;then add scale=0 to bc.&lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;a=19&lt;BR /&gt;b=17&lt;BR /&gt;&lt;BR /&gt;s1=$(echo "scale=0;($a/31)*100" | bc -l)&lt;BR /&gt;s2=$(echo "scale=0;($b/31)*100" | bc -l)&lt;BR /&gt;&lt;BR /&gt;#s1=$(awk 'BEGIN{printf "%2.0f\n",($a/31)*100}')&lt;BR /&gt;#s2=$(awk 'BEGIN{printf "%2.0f\n",($b/31)*100}')&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if [ $s1 -gt $s2 ]; then echo "Holiday"&lt;BR /&gt;else echo "More work"&lt;BR /&gt;fi&lt;BR /&gt;</description>
    <pubDate>Fri, 21 Nov 2008 12:14:59 GMT</pubDate>
    <dc:creator>Ivan Ferreira</dc:creator>
    <dc:date>2008-11-21T12:14:59Z</dc:date>
    <item>
      <title>bc doesnt do maths</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310201#M62723</link>
      <description>&lt;BR /&gt;(15/31)*100 = 48.387096774&lt;BR /&gt;or&lt;BR /&gt;(15/31)*100 = 48&lt;BR /&gt;&lt;BR /&gt;how can I do the above maths using shell script ?&lt;BR /&gt;&lt;BR /&gt;bc  say/produce '0' when 15 is divided by  31&lt;BR /&gt;&lt;BR /&gt;please help&lt;BR /&gt;Regards</description>
      <pubDate>Thu, 20 Nov 2008 13:11:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310201#M62723</guid>
      <dc:creator>Maaz</dc:creator>
      <dc:date>2008-11-20T13:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: bc doesnt do maths</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310202#M62724</link>
      <description>You can use:&lt;BR /&gt;&lt;BR /&gt;echo "(15/31)*100" | bc -l&lt;BR /&gt;</description>
      <pubDate>Thu, 20 Nov 2008 13:38:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310202#M62724</guid>
      <dc:creator>Ivan Ferreira</dc:creator>
      <dc:date>2008-11-20T13:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: bc doesnt do maths</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310203#M62725</link>
      <description>I believe you can do it like this:&lt;BR /&gt;echo "scale=2; (15/31)*100" | bc&lt;BR /&gt;&lt;BR /&gt;the scale=2 is just to tell bc that you want only 2 decimals.&lt;BR /&gt;&lt;BR /&gt;quote from &lt;A href="http://www.kingcomputerservices.com/unix_101/using_bc_part_1.htm" target="_blank"&gt;http://www.kingcomputerservices.com/unix_101/using_bc_part_1.htm&lt;/A&gt;&lt;BR /&gt;"The number of decimals to be printed by bc is controlled by the scale variable. The default scale is 0."&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Fredrik Eriksson</description>
      <pubDate>Thu, 20 Nov 2008 13:39:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310203#M62725</guid>
      <dc:creator>Fredrik.eriksson</dc:creator>
      <dc:date>2008-11-20T13:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: bc doesnt do maths</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310204#M62726</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;If you want to use 'bc' add the 'scale' factor to define the number of digits to the right of the decimal place:&lt;BR /&gt;&lt;BR /&gt;# echo "scale=9;(15/31)*100"| bc&lt;BR /&gt;48.387096700&lt;BR /&gt;&lt;BR /&gt;Other ways to accomplish your task, include 'awk' and 'perl' or a shell line Korn93 that supports real numbers:&lt;BR /&gt;&lt;BR /&gt;# awk 'BEGIN{printf "%2.9f\n",(15/31)*100}'&lt;BR /&gt;48.387096774&lt;BR /&gt;&lt;BR /&gt;# perl -e 'printf "%2.9f\n",(15/31)*100'&lt;BR /&gt;48.387096774&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Thu, 20 Nov 2008 13:41:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310204#M62726</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-11-20T13:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: bc doesnt do maths</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310205#M62727</link>
      <description>thanks everyone for nice help ;)&lt;BR /&gt;&lt;BR /&gt;please help me in the following code&lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;a=19&lt;BR /&gt;b=17&lt;BR /&gt;&lt;BR /&gt;s1=$(echo "($a/31)*100" | bc -l)&lt;BR /&gt;s2=$(echo "($b/31)*100" | bc -l)&lt;BR /&gt;&lt;BR /&gt;#s1=$(awk 'BEGIN{printf "%2.0f\n",($a/31)*100}')&lt;BR /&gt;#s2=$(awk 'BEGIN{printf "%2.0f\n",($b/31)*100}')&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if [ $s1 -gt $s2 ]; then echo "Holiday"&lt;BR /&gt;   else echo "More work"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Fri, 21 Nov 2008 11:48:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310205#M62727</guid>
      <dc:creator>Maaz</dc:creator>
      <dc:date>2008-11-21T11:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: bc doesnt do maths</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310206#M62728</link>
      <description>If your error is:&lt;BR /&gt;&lt;BR /&gt;line 12: [: 61.29032258064516129000: integer expression expected&lt;BR /&gt;&lt;BR /&gt;then add scale=0 to bc.&lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;a=19&lt;BR /&gt;b=17&lt;BR /&gt;&lt;BR /&gt;s1=$(echo "scale=0;($a/31)*100" | bc -l)&lt;BR /&gt;s2=$(echo "scale=0;($b/31)*100" | bc -l)&lt;BR /&gt;&lt;BR /&gt;#s1=$(awk 'BEGIN{printf "%2.0f\n",($a/31)*100}')&lt;BR /&gt;#s2=$(awk 'BEGIN{printf "%2.0f\n",($b/31)*100}')&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if [ $s1 -gt $s2 ]; then echo "Holiday"&lt;BR /&gt;else echo "More work"&lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Fri, 21 Nov 2008 12:14:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310206#M62728</guid>
      <dc:creator>Ivan Ferreira</dc:creator>
      <dc:date>2008-11-21T12:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: bc doesnt do maths</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310207#M62729</link>
      <description>&amp;gt;If your error is:&lt;BR /&gt;&amp;gt;line 12: [: 61.29032258064516129000: integer expression expected&lt;BR /&gt;&lt;BR /&gt;&amp;gt;then add scale=0 to bc.&lt;BR /&gt;&lt;BR /&gt;vi script.sh&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;s1=$(echo "scale=0;($a/31)*100" | bc -l)&lt;BR /&gt;s2=$(echo "scale=0;($b/31)*100" | bc -l)&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;&lt;BR /&gt;# bash -x script.sh&lt;BR /&gt;+ a=19&lt;BR /&gt;+ b=17&lt;BR /&gt;++ echo 'scale=0;(19/31)*100'&lt;BR /&gt;++ bc -l&lt;BR /&gt;+ s1=0&lt;BR /&gt;++ echo 'scale=0;(17/31)*100'&lt;BR /&gt;++ bc -l&lt;BR /&gt;+ s2=0&lt;BR /&gt;+ '[' 0 -gt 0 ']'&lt;BR /&gt;+ echo 'More work'&lt;BR /&gt;More work&lt;BR /&gt;&lt;BR /&gt;when using "scale=0", you can check/see that s1 and s2 both equals to 0&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;</description>
      <pubDate>Sat, 22 Nov 2008 04:47:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310207#M62729</guid>
      <dc:creator>Maaz</dc:creator>
      <dc:date>2008-11-22T04:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: bc doesnt do maths</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310208#M62730</link>
      <description>You are right, there may be better ways, but you can do:&lt;BR /&gt;&lt;BR /&gt;echo "(17/31)*100" | bc -l | cut -f 1 -d "."&lt;BR /&gt;&lt;BR /&gt;To remove the decimals.</description>
      <pubDate>Mon, 24 Nov 2008 02:46:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bc-doesnt-do-maths/m-p/4310208#M62730</guid>
      <dc:creator>Ivan Ferreira</dc:creator>
      <dc:date>2008-11-24T02:46:32Z</dc:date>
    </item>
  </channel>
</rss>

