<?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: VB.Net changes double values when converted to string in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286011#M7386</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;These are great suggestions on handling it but i still need to query for the original number somehow.&amp;nbsp; Is there a way to to this the other way; to "elegantly" incorporate such tolerance in a query other than using BETWEEN?&amp;nbsp; Would a wildcard character work on a number for example something like&amp;nbsp; Shape_Area IN (987.87676%,876.7655%,564.987675%)&amp;nbsp; or if I round the numbers beforehand is there a way to query rounded number for example ROUND(Shape_Area, 6) IN (987.876765,876.76553,564.9876754) &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 25 Jun 2016 17:01:50 GMT</pubDate>
    <dc:creator>JakubSisak</dc:creator>
    <dc:date>2016-06-25T17:01:50Z</dc:date>
    <item>
      <title>VB.Net changes double values when converted to string</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286007#M7382</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am have an issue in my addin; I need to construct a defenition query from Shape_Area, Shape_Langth and other values but when these numbers are converted to string in any way the resulting number is most often rouded to less decimal places than those in the the source feature class.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example: the actual value in pRow.Value(i) = 1234.12345678987656&amp;nbsp; but the result of pRow.Value(i).ToString = 1234.123456789877&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas?&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Jun 2016 14:17:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286007#M7382</guid>
      <dc:creator>JakubSisak</dc:creator>
      <dc:date>2016-06-25T14:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: VB.Net changes double values when converted to string</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286008#M7383</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;welcome to floating point representation... you are perceiving false precision.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A demonstration using python which has well behaved numerical properties&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; a = 1234.12345678987656000
&amp;gt;&amp;gt;&amp;gt; a
1234.1234567898766
&amp;gt;&amp;gt;&amp;gt; "{:&amp;lt;20.16f}".format(a)
'1234.1234567898766272'
&amp;gt;&amp;gt;&amp;gt; "{:&amp;lt;20.18f}".format(a)
'1234.123456789876627226'
&amp;gt;&amp;gt;&amp;gt; a-a
0.0
&amp;gt;&amp;gt;&amp;gt; "{:&amp;lt;20.18f}".format(a-a)
'0.000000000000000000'&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not weird enough for you?&amp;nbsp; How about one of the most robust numeric modules available... got to be great eh???&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; from decimal import Decimal
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; a = 1234.12345678987656&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # 14 decimals 
&amp;gt;&amp;gt;&amp;gt; Decimal(a)
Decimal('1234.123456789876627226476557552814483642578125')
&amp;gt;&amp;gt;&amp;gt; b = 1234.12345678987650&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # 14 decimals, drop the ....6 at the end
&amp;gt;&amp;gt;&amp;gt; Decimal(b)
Decimal('1234.1234567898763998528011143207550048828125')
&amp;gt;&amp;gt;&amp;gt; Decimal(b)-Decimal(a)
Decimal('-2.273736754432320594787597656E-13')
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In conclusion.... hmmmm not all is as it seems&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:49:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286008#M7383</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T13:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: VB.Net changes double values when converted to string</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286009#M7384</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Dan!&amp;nbsp; Not a good news. Is there a solution/workaround?&amp;nbsp; I need to print the values as string (and concatenate a simple but long FIELD IN (value, value, value,...) statement to make a definition query that will return the records whose values are used in this query.&amp;nbsp; Is there a way to handle false precision especially when shape area and length are involved? The interesting thing is that when I use the Query builder in the attribute table and hit the unique values button - they all seem to be correct - building a similar query with these values in the Attribute Table Query Builder always works correctly. This is essentially the same values I need but when I convert them to string in VB.Net those values are slightly changed hence making my own query unusable. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Jun 2016 15:47:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286009#M7384</guid>
      <dc:creator>JakubSisak</dc:creator>
      <dc:date>2016-06-25T15:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: VB.Net changes double values when converted to string</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286010#M7385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When querying floating point numbers, it is best to specify a tolerance around your number rather than the exact number&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; a = 1234.1234567890123456
&amp;gt;&amp;gt;&amp;gt; a
1234.1234567890124
&amp;gt;&amp;gt;&amp;gt; s = str(a)
&amp;gt;&amp;gt;&amp;gt; s
'1234.1234567890124'
&amp;gt;&amp;gt;&amp;gt; str(a)==s
True&lt;/PRE&gt;&lt;P&gt;Now compare the float to the float version of the string&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; a == float(s)
True
or use a tolerance
&amp;gt;&amp;gt;&amp;gt; b = 1234.1234567890123
&amp;gt;&amp;gt;&amp;gt; a = 1234.1234567890123456
&amp;gt;&amp;gt;&amp;gt; tol = 1e-12
&amp;gt;&amp;gt;&amp;gt; a-tol &amp;lt; b &amp;lt; a+tol
True&lt;/PRE&gt;&lt;P&gt;I just wanted to point out the problems you might encounter with the string representation of floating point numbers.&amp;nbsp; In most cases, things are ignored, other times they aren't.&amp;nbsp; Python is well behaved, I can't remember if VB or its incarnations were as robust since I never really used it much.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So user beware, if things go wrong, you will at least know why they went wrong and how to check for them.&amp;nbsp; There are other options as well should none of these work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:49:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286010#M7385</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T13:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: VB.Net changes double values when converted to string</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286011#M7386</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;These are great suggestions on handling it but i still need to query for the original number somehow.&amp;nbsp; Is there a way to to this the other way; to "elegantly" incorporate such tolerance in a query other than using BETWEEN?&amp;nbsp; Would a wildcard character work on a number for example something like&amp;nbsp; Shape_Area IN (987.87676%,876.7655%,564.987675%)&amp;nbsp; or if I round the numbers beforehand is there a way to query rounded number for example ROUND(Shape_Area, 6) IN (987.876765,876.76553,564.9876754) &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Jun 2016 17:01:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286011#M7386</guid>
      <dc:creator>JakubSisak</dc:creator>
      <dc:date>2016-06-25T17:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: VB.Net changes double values when converted to string</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286012#M7387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ROUND( SHAPE_Area,2) IN (&amp;nbsp; 0.21,&amp;nbsp; 244163503.16 )&amp;nbsp; is in fact a valid query.&amp;nbsp; I can work with that. Thanks for pointing me in the right direction. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Jun 2016 17:20:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286012#M7387</guid>
      <dc:creator>JakubSisak</dc:creator>
      <dc:date>2016-06-25T17:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: VB.Net changes double values when converted to string</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286013#M7388</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Using rounding and comparing rounded pairs helped but didn't work 100%.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Jul 2016 13:44:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286013#M7388</guid>
      <dc:creator>JakubSisak</dc:creator>
      <dc:date>2016-07-11T13:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: VB.Net changes double values when converted to string</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286014#M7389</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Format your string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://msdn.microsoft.com/en-us/library/kfsatb94(v=vs.110).aspx" title="https://msdn.microsoft.com/en-us/library/kfsatb94(v=vs.110).aspx"&gt;Double.ToString Method (String) (System)&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Jul 2016 14:28:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-changes-double-values-when-converted-to/m-p/286014#M7389</guid>
      <dc:creator>TedKowal</dc:creator>
      <dc:date>2016-07-11T14:28:45Z</dc:date>
    </item>
  </channel>
</rss>

