public static String printBin(double num) { StringBuffer str = new StringBuffer(); str.append(‘0‘); str.append(‘.‘); while(num != 0.0){ num = num * 2; if(str.length() >= 32){ return "Error"; } str.append((int)num); num = num - (int)num; } return str.toString(); }
原文:http://www.cnblogs.com/yueyebigdata/p/5073421.html