? ? ? ? 使用double和float類(lèi)型數(shù)據(jù)時(shí),會(huì)產(chǎn)生數(shù)據(jù)不精準(zhǔn)的問(wèn)題砍鸠,這時(shí)可以使用BigDecimal進(jìn)行處理爷辱。
? ??????double a=new Scanner(System.in).nextDouble();
????????double b=new Scanner(System.in).nextDouble();
????????BigDecimal d1=new BigDecimal(a+"");
????????BigDecimal d2=new BigDecimal(b+"");
????????System.out.println(d1.add(d2));
? ? ? ? 注意的是弟断,一定要在括號(hào)中使用變量+“”,使數(shù)據(jù)變成一個(gè)字符串類(lèi)型浸踩,不然還是會(huì)出現(xiàn)數(shù)據(jù)不精確的情況微驶。
? ??????
? ??????