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
