java BigDecimal add 等方法遇到的問題

來源:互聯網
上載者:User

標籤:print   代碼   應該   輸出   java   自己   out   system   nbsp   

 1 //這篇隨筆是為了提醒自己避免重複錯誤 2  3  4  5 //原先的代碼是這樣的,想著輸出會是9.00,可是結果卻是0.00 6 BigDecimal day_fee = new BigDecimal("0.00"); 7 day_fee.add( new BigDecimal("9.00")); 8 System.out.print("day_fee:" + day_fee); 9 10 //正確的代碼應該是這樣的,輸出的是9.00,BigDecimal使用方法自身不會改變,沒想到居然被糊弄了11 BigDecimal day_fee = new BigDecimal("0.00");12 day_fee = day_fee.add( new BigDecimal("9.00"));13 System.out.print("day_fee:" + day_fee);14 15 //然後BigDecimal其他的方法也是具有類似情況16 17 //附:發現了BigDecimal一個自身轉負數的方法18 day_fee = day_fee.negate();

 

java BigDecimal add 等方法遇到的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.