<p>Both are mathematical values, however the float does have more precision. Is that the only reason for the error - the difference in precision? Or is there another potential (and more serious) problem?</p>

[{'answer_id': 38030, 'author': 'DrPizza', 'author_id': 2131, 'author_profile': 'https://Stackoverflow.com/users/2131', 'pm_score': 2, 'selected': False, 'text': "<p>Because it probably isn't a very good idea.  Not all floats can be truncated to ints; not all ints can be converted to floats.</p>\n"}, {'answer_id': 38033, 'author': 'Skizz', 'author_id': 1898, 'author_profile': 'https://Stackoverflow.com/users/1898', 'pm_score': 4, 'selected': True, 'text': "<p>It's because the set of integer values does not equal the set of float values for the 'int' and 'float' types. For example, the float value 0.5 has no equal in the integer set and the integer value 4519245367 might not exist in the set of values a float can store. So, the checker flags this as an issue to be checked by the programmer.</p>\n"}, {'answer_id': 38036, 'author': 'Paul Tomblin', 'author_id': 3333, 'author_profile': 'https://Stackoverflow.com/users/3333', 'pm_score': 1, 'selected': False, 'text': '<p>Because floats can\'t store an exact int value, so if you have two variables, int i and float f, even if you assign "i = f;", the comparison "if (i == f)" probably won\'t return true.</p>\n'}, {'answer_id': 38044, 'author': 'Tim Ring', 'author_id': 3685, 'author_profile': 'https://Stackoverflow.com/users/3685', 'pm_score': 0, 'selected': False, 'text': '<p>If you need to get around this (you have a legitimate reason and are happy none of the issues mentioned in the other answers are an issue for you) then just cast from one type to another.</p>\n'}, {'answer_id': 43486, 'author': 'smh', 'author_id': 1077, 'author_profile': 'https://Stackoverflow.com/users/1077', 'pm_score': 1, 'selected': False, 'text': '<p>Assuming signed integers and IEEE floating point format, the magnitudes of integers that can be represented are:</p>\n\n<pre><code>short  -&gt; 15 bits\nfloat  -&gt; 23 bits\nlong   -&gt; 31 bits\ndouble -&gt; 52 bits\n</code></pre>\n\n<p>Therefore a <code>float</code> can represent any <code>short</code> and a <code>double</code> can represent any <code>long</code>.</p>\n'}, {'answer_id': 181446, 'author': 'Chris Arguin', 'author_id': 25704, 'author_profile': 'https://Stackoverflow.com/users/25704', 'pm_score': 2, 'selected': False, 'text': '<p>When doing the comparison, the integer value will get "promoted" to a floating point value. At that point you are doing a exact equality comparison between two floating point numbers, which is almost always a bad thing. </p>\n\n<p>You should generally have some sort of "epsilon ball", or range of acceptable values, and you do the comparison if the two vaues are close enough to each other to be considered equal. You need a function roughly like this:</p>\n\n<pre><code>int double_equals(double a, double b, double epsilon)\n{\n   return ( a &gt; ( b - epsilon ) &amp;&amp; a &lt; ( b + epsilon ) );\n}\n</code></pre>\n\n<p>If your application doesn\'t have an obvious choice of epsilon, then use DBL_EPSILON. </p>\n'}]
['https://Stackoverflow.com/questions/38027', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/572/']