Java double to string
•
Java
< 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);">static</span> <span class="hljs-keyword" style="color:rgb(0,136);">void</span> <span class="hljs-title">test1</span>(<span class="hljs-keyword" style="color:rgb(0,136);">double</span> dou) {
String dou_str = Double.toString(dou);
<span class="hljs-keyword" style="color:rgb(0,136);">if</span> (dou_str.equals(<span class="hljs-string" style="color:rgb(0,136,0);">"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);">out</span>.println(<span class="hljs-string" style="color:rgb(0,0);">"YES!"</span>);
} <span class="hljs-keyword" style="color:rgb(0,136);">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);">"NO!"</span>);
}
}
<span class="hljs-keyword" style="color:rgb(0,136);">void</span> <span class="hljs-title">main</span>(String[] args) {
<span class="hljs-keyword" style="color:rgb(0,136);">double</span> dou = <span class="hljs-number" style="color:rgb(0,102,102);">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
二维码