实例24 大数高精度
java的大数高精度计算时非常方便的。
BigDecimal类中:
add:加法
subtract:减法
multiply:乘法
divide:除法
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package test; import java.io.FileNotFoundException; import java.io.InputStream; import java.io.PrintStream; import java.math.BigDecimal; import java.util.Scanner; import com.sun.org.apache.bcel.internal.generic.NEW; /** * @author 年浩 * */ public class test { public static void main(String[] args) { // TODO Auto-generated method stub double money=2; double price = 1.1; double result = money-price; System.out.println("非精确计算:"); System.out.println("剩余金额:"+result); BigDecimal money1 = new BigDecimal("2"); BigDecimal price1 = new BigDecimal("1.1"); BigDecimal result1 = money1.subtract(price1); System.out.println("精确计算:"); System.out.println("剩余金额:"+result1); } }