Java double to string

< a href="%20http://lib.csdn.net/base/java%20" rel="nofollow" class="replace_ Word "title =" java knowledge base "style =" text decoration: none; color:rgb(223,52,52); font-weight:bold; "> in Java, double.tostring (d) can be used to convert double to string. However, this method has hidden pits. Please take a closer look:

public class DoubleToString {

<span class="hljs-keyword" style="color:rgb(0,136);"&gt;static</span> <span class="hljs-keyword" style="color:rgb(0,136);"&gt;void</span> <span class="hljs-title"&gt;test1</span>(<span class="hljs-keyword" style="color:rgb(0,136);"&gt;double</span> dou) {
    String dou_str = Double.toString(dou);
    <span class="hljs-keyword" style="color:rgb(0,136);"&gt;if</span> (dou_str.equals(<span class="hljs-string" style="color:rgb(0,136,0);"&gt;"20160101"</span>)) {
        Sy<a href="https://www.jb51.cc/tag/stem/" target="_blank" class="keywords">stem</a>.<span class="hljs-keyword" style="color:rgb(0,136);"&gt;out</span>.println(<span class="hljs-string" style="color:rgb(0,0);"&gt;"YES!"</span>);
    } <span class="hljs-keyword" style="color:rgb(0,136);"&gt;else</span> {
        Sy<a href="https://www.jb51.cc/tag/stem/" target="_blank" class="keywords">stem</a>.<span class="hljs-keyword" style="color:rgb(0,0);"&gt;"NO!"</span>);
    }
}

<span class="hljs-keyword" style="color:rgb(0,136);"&gt;void</span> <span class="hljs-title"&gt;main</span>(String[] args) {
    <span class="hljs-keyword" style="color:rgb(0,136);"&gt;double</span> dou = <span class="hljs-number" style="color:rgb(0,102,102);"&gt;20160101</span>;
    test1(dou);
}

}

    :
    YES!
    The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
    THE END
    分享
    二维码
    < <上一篇
    下一篇>>