科学计数法转换为数字型字符串

@Test
public void test3() {
    //科学计数法数字 转 普通数字字符串
    double num1 = 50123.12E8;
    BigDecimal bd1 = new BigDecimal(num1);
    System.out.println(bd1.toPlainString());  //5012312000000
    System.out.println(bd1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());  //5012312000000.00
    //BigDecimal普通数字
    double num2 = 50123.12;
    BigDecimal bd2 = new BigDecimal(num2);
    System.out.println(bd2.toPlainString());    //50123.1200000000026193447411060333251953125
    System.out.println(bd2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());  //50123.12
}

你可能感兴趣的:(Java)