BigDecimal 实际测试结果
package com.zzzy; import java.math.BigDecimal; public class Test { public static void main(String[] args) { BigDecimal hundred = new BigDecimal(100); BigDecimal bd1 = new BigDecimal(1); BigDecimal bd2 = new BigDecimal("2"); BigDecimal bd3 = new BigDecimal("3.0"); BigDecimal bd4 = new BigDecimal("4.00"); BigDecimal bd5 = new BigDecimal("05.0"); BigDecimal bd6 = new BigDecimal("6.005"); BigDecimal bd7 = new BigDecimal(6.005); System.out.println(bd1); System.out.println(bd2); System.out.println(bd3); System.out.println(bd4); System.out.println(bd5); System.out.println(bd6); System.out.println(bd7); System.out.println("-----------------------"); System.out.println(bd7.compareTo(bd6)); System.out.println("-----------------------"); System.out.println(bd1.multiply(hundred)); System.out.println(bd2.multiply(hundred)); System.out.println(bd3.multiply(hundred)); System.out.println(bd4.multiply(hundred)); System.out.println(bd5.multiply(hundred)); System.out.println(bd6.multiply(hundred)); System.out.println(bd7.multiply(hundred)); } }
输出结果:
1 2 3.0 4.00 5.0 6.005 6.00499999999999989341858963598497211933135986328125 ----------------------- -1 ----------------------- 100 200 300.0 400.00 500.0 600.500 600.49999999999998934185896359849721193313598632812500