Strange behavior when converting a double to String in Java
<p>I have a crash in my Android application coming from a strange behavior in a SQL query string construction. Here is the error:</p>

<pre><code>Caused by: android.database.sqlite.SQLiteException: near ")": syntax error: , while
compiling: SELECT [...], (0.6773931613745379*coslat*(coslng*0.9999276712889913
+sinlng*0.012027143*)+0.7356211694364222*sinlat) [...]
</code></pre>

<p>The errors comes precisely from here:  <code>sinlng*0.012027143*)</code> &lt;== *) at the end</p>

<p>This string is builded by the following function:</p>

<pre><code>public static String buildDistanceQuery(double latitude, double longitude) {
    final double coslat = Math.cos(MathUtils.deg2rad(latitude));
    final double sinlat = Math.sin(MathUtils.deg2rad(latitude));
    final double coslng = Math.cos(MathUtils.deg2rad(longitude));
    final double sinlng = Math.sin(MathUtils.deg2rad(longitude));
    return "(" + coslat + "*" + LocationColumns.COSLAT
            + "*(" + LocationColumns.COSLNG + "*" + coslng
            + "+" + LocationColumns.SINLNG + "*" + sinlng
            + ")+" + sinlat + "*" + LocationColumns.SINLAT 
            + ")";
}
</code></pre>

<p>As you can see, <code>LocationColumns.SINLNG + "*" + sinlng + ")"</code> becomes <code>sinlng*0.012027143*)</code> and I really don't see how this could be possible as sinlng is a double...</p>

<p>I cannot reproduce the problem, the crash comes from Android Market console and I do not have all the context. It is not a unique crash, I got multiple occurences.</p>

<p>I can try to use a StringBuilder() but I'm not sure it will correct the issue.</p>

<p>Do someone has a clue of how a double can generate a "*" when converted to String?</p>
