import java.math.BigDecimal; import java.util.Scanner; /** * Created by Administrator on 2016/9/20. */ public class BigDecimalGetNumbers { public static void main(String args[]) { Scanner in = new Scanner(System.in); double dInput = in.nextDouble(); long longPart = (long) dInput; BigDecimal bigDecimal = new BigDecimal(Double.toString(dInput)); BigDecimal bigDecimalLongPart = new BigDecimal(Double.toString(longPart)); double dPoint = bigDecimal.subtract(bigDecimalLongPart).doubleValue(); System.out.println("整数部分为:" + longPart + "\n" + "小数部分为: " + dPoint); } }
测试数据:1.234567E4
1.234567E4 整数部分为:12345 小数部分为: 0.67 Process finished with exit code 0
时间: 2024-10-14 21:09:14