<?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 Issue in converting character string to float, double. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/issue-in-converting-character-string-to-float-double/m-p/5014649#M772610</link>
    <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;   The below mentioned code is running on a HP-UX machine and is giving output as shown below. I could not figure out the reason for getting [641.330017] instead of [641.330000].&lt;BR /&gt;&lt;BR /&gt;Can some body please point out the reason for this?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Saurav&lt;BR /&gt;&lt;BR /&gt;Code:&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;&lt;BR /&gt;int main(void)&lt;BR /&gt;{&lt;BR /&gt;    char *cpStr = "00000641.33";&lt;BR /&gt;&lt;BR /&gt;    float f = 0.0;&lt;BR /&gt;    double d = 0.0;&lt;BR /&gt;    double e = 0.0;&lt;BR /&gt;    float g = 0.0;&lt;BR /&gt;&lt;BR /&gt;    f = (float)atof(cpStr);&lt;BR /&gt;    d = (double)atof(cpStr);&lt;BR /&gt;    e = atof(cpStr);&lt;BR /&gt;    g = atof(cpStr);&lt;BR /&gt;&lt;BR /&gt;    printf("\n cpStr = [%s] f = [%f] d = [%f] [e] = [%f] [g] = [%f] ... \n\n",cpStr,f,d,e,g);&lt;BR /&gt;&lt;BR /&gt;    e = 641.33;&lt;BR /&gt;    f = (float)e;&lt;BR /&gt;&lt;BR /&gt;    printf("\n [e] = [%f] f = [%f] ... \n\n",e,f);&lt;BR /&gt;&lt;BR /&gt;    exit(0);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Output :&lt;BR /&gt;&lt;BR /&gt; cpStr = [00000641.33] f = [641.330017] d = [641.330000] [e] = [641.330000] [g] = [641.330017] ...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; [e] = [641.330000] f = [641.330017] ...&lt;BR /&gt;&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;</description>
    <pubDate>Fri, 17 Nov 2006 08:07:19 GMT</pubDate>
    <dc:creator>Saurav_Narain</dc:creator>
    <dc:date>2006-11-17T08:07:19Z</dc:date>
    <item>
      <title>Issue in converting character string to float, double.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/issue-in-converting-character-string-to-float-double/m-p/5014649#M772610</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;   The below mentioned code is running on a HP-UX machine and is giving output as shown below. I could not figure out the reason for getting [641.330017] instead of [641.330000].&lt;BR /&gt;&lt;BR /&gt;Can some body please point out the reason for this?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Saurav&lt;BR /&gt;&lt;BR /&gt;Code:&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;&lt;BR /&gt;int main(void)&lt;BR /&gt;{&lt;BR /&gt;    char *cpStr = "00000641.33";&lt;BR /&gt;&lt;BR /&gt;    float f = 0.0;&lt;BR /&gt;    double d = 0.0;&lt;BR /&gt;    double e = 0.0;&lt;BR /&gt;    float g = 0.0;&lt;BR /&gt;&lt;BR /&gt;    f = (float)atof(cpStr);&lt;BR /&gt;    d = (double)atof(cpStr);&lt;BR /&gt;    e = atof(cpStr);&lt;BR /&gt;    g = atof(cpStr);&lt;BR /&gt;&lt;BR /&gt;    printf("\n cpStr = [%s] f = [%f] d = [%f] [e] = [%f] [g] = [%f] ... \n\n",cpStr,f,d,e,g);&lt;BR /&gt;&lt;BR /&gt;    e = 641.33;&lt;BR /&gt;    f = (float)e;&lt;BR /&gt;&lt;BR /&gt;    printf("\n [e] = [%f] f = [%f] ... \n\n",e,f);&lt;BR /&gt;&lt;BR /&gt;    exit(0);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Output :&lt;BR /&gt;&lt;BR /&gt; cpStr = [00000641.33] f = [641.330017] d = [641.330000] [e] = [641.330000] [g] = [641.330017] ...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; [e] = [641.330000] f = [641.330017] ...&lt;BR /&gt;&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Fri, 17 Nov 2006 08:07:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/issue-in-converting-character-string-to-float-double/m-p/5014649#M772610</guid>
      <dc:creator>Saurav_Narain</dc:creator>
      <dc:date>2006-11-17T08:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: Issue in converting character string to float, double.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/issue-in-converting-character-string-to-float-double/m-p/5014650#M772612</link>
      <description>&lt;BR /&gt;Single float is stored in just 32 bits. Ther is only so much precision you get with that.&lt;BR /&gt;Roughly that precision is 9 places, but not all number can be stored exactly. Thus the 'odd rounding'.&lt;BR /&gt;&lt;BR /&gt;Read teh following carefully: &lt;BR /&gt;&lt;A href="http://docs.hp.com/en/B3906-90006/ch02s02.html" target="_blank"&gt;http://docs.hp.com/en/B3906-90006/ch02s02.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Nov 2006 08:24:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/issue-in-converting-character-string-to-float-double/m-p/5014650#M772612</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2006-11-17T08:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Issue in converting character string to float, double.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/issue-in-converting-character-string-to-float-double/m-p/5014651#M772614</link>
      <description>&lt;!--!*#--&gt;&amp;gt;Hein: Thus the 'odd rounding'.&lt;BR /&gt;&lt;BR /&gt;Right.&lt;BR /&gt;If you asked printf to round to only 2 digits, it would print it "better":&lt;BR /&gt;   printf("f = [%.2f]\n",f);&lt;BR /&gt;f = [641.33]&lt;BR /&gt;&lt;BR /&gt;If you want to see what's in a float vs a double, you could use the %a format on IPF to print it in hex.&lt;BR /&gt;   printf("f = [%.2f] f = [%a] d = [%a] \n",f,f,d);&lt;BR /&gt;f = [641.33] f = [0x1.40aa3e0000000p+9] d = [0x1.40aa3d70a3d71p+9]</description>
      <pubDate>Fri, 17 Nov 2006 21:25:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/issue-in-converting-character-string-to-float-double/m-p/5014651#M772614</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2006-11-17T21:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Issue in converting character string to float, double.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/issue-in-converting-character-string-to-float-double/m-p/5014652#M772616</link>
      <description>Thanks you.</description>
      <pubDate>Sat, 25 Nov 2006 00:11:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/issue-in-converting-character-string-to-float-double/m-p/5014652#M772616</guid>
      <dc:creator>Saurav_Narain</dc:creator>
      <dc:date>2006-11-25T00:11:21Z</dc:date>
    </item>
  </channel>
</rss>

