我很驚訝看到下面的程序,請告知它如何表現如此,因爲我非常認同poitn精確到小數點後,下面是progrmam小數點精度丟失對於一些雙數據類型的情況下的某些munbers
double fixedRate = 0.997500000000; //**output --->0.9975
// BigDecimal fixedRate = new BigDecimal("0.997500000000");
double fixedRate1 = 0.123456789;
System.out.println(fixedRate);
System.out.println(fixedRate1);
和輸出
0.9975
0.123456789
現在請大家指教爲先輸出中是0.9975,但尾盤爲下它不是小數點後截斷,但爲什麼第一次呢。
看一看教程就如何格式化數字https://docs.oracle.com/javase/tutorial/java/data /numberformat.html – Kennet
沒有那是不同的事我同意謝謝你的建議 – user1508454
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html閱讀並重讀,直到你完全理解 – jwenting