我想知道为什么与下面的代码不一致。我期望得到相同的输出,但是当使用内联条件语句时,它会向该字符串附加一个.0。 我的代码中有一些错误吗?使用内联条件语句格式化小数
double d = 10.1;
String rounded = (false ? d : Math.round(d)) + "";
System.out.println(rounded);//10.0
rounded = Math.round(d) + "";
System.out.println(rounded);//10
为JLS链接投票。谢谢! – bradvido
同上1+的链接和非常明确的答案。 –
不错的视频链接..谢谢 – bradvido