Float greater or less than zero
<p>I have the following code which sometimes return as true and sometimes doesn't.</p>

<p>Any idea what might be causing the varying result?</p>

<p>The 0.00 string comes from a JSON object.</p>

<p><em>(code simplified)</em></p>

<pre><code>if(new Float("0.00")&gt;0){
    // do something
}
</code></pre>

<p>EDIT:</p>

<p>What I have is some floats which I want to determine if its zero, less than zero or more than zero. The values could be stuff like 0.00, 0.001 or -0.001. How do I determine whether whether they are positive, negative or zero?</p>

<p>EDIT:</p>

<p>Perhaps I should clarify how I get the values. I might be totally something else that is causing the problem because I read about BigDecimal and tried to use it to no avail.</p>

<p>The values are extracted from a JSON feed (which has this format LT:0.000) using this code:</p>

<pre><code>price = new BigDecimal(stocksJSONArray.getJSONObject(i).getString("LT"));
</code></pre>

<p>Then to test if price is greater or less than zero, I used the following conditional statements:</p>

<pre><code>if(price.compareTo(BigDecimal.ZERO)==1){
    // greater than zero
}
else if(price.compareTo(BigDecimal.ZERO)==-1){
    // less than zero
}
</code></pre>

<p>This code is looped for many values read out from the JSON feed. And from the results, some <code>price</code> which is zero gets processed as greater than zero and some gets processed as less than zero. I'm suspecting that something else is causing the problem here?</p>

<p>I also did a test to see if the problem was with the accuracy of the data. So I did this:</p>

<pre><code>DecimalFormat frmt = new DecimalFormat("0.000000000000000000000000");
String formatted = frmt.format(stock.change);
</code></pre>

<p>And for the zeros that got recognized as positives and negatives, the trace value for it was still <code>0.000000000000000000000000</code>, not <code>0.000000000000000000000001</code> or something like that.</p>
