美文网首页android 技术知识
android中如何将Double类型转换成Integer类型

android中如何将Double类型转换成Integer类型

作者: 追梦小乐 | 来源:发表于2017-09-23 12:57 被阅读5次

    记录一下这个知识点,不然老是忘记

    (Double.valueOf(positionDataResponse.acb21i).intValue()
    

    来都来了不妨看一下源码吧

        public static Double valueOf(String string) throws NumberFormatException {
            return parseDouble(string);
        }
    
        public static double parseDouble(String string) throws NumberFormatException {
            return StringToReal.parseDouble(string);
        }
    
     public static double parseDouble(String s) {
            s = s.trim();
            int length = s.length();
    
            if (length == 0) {
                throw invalidReal(s, true);
            }
    
            // See if this could be a named double
            char last = s.charAt(length - 1);
            if (last == 'y' || last == 'N') {
                return parseName(s, true);
            }
    
            // See if it could be a hexadecimal representation.
            // We don't use startsWith because there might be a leading sign.
            if (s.indexOf("0x") != -1 || s.indexOf("0X") != -1) {
                return HexStringParser.parseDouble(s);
            }
    
            StringExponentPair info = initialParse(s, length, true);
            if (info.infinity || info.zero) {
                return info.specialValue();
            }
            double result = parseDblImpl(info.s, (int) info.e);
            if (Double.doubleToRawLongBits(result) == 0xffffffffffffffffL) {
                throw invalidReal(s, true);
            }
            return info.negative ? -result : result;
        }
    
    //当你用Integer.valueof("2500.0")时就会出现
        private static NumberFormatException invalidReal(String s, boolean isDouble) {
            throw new NumberFormatException("Invalid " + (isDouble ? "double" : "float") + ": \"" + s + "\"");
        }
    
    

    相关文章

      网友评论

        本文标题:android中如何将Double类型转换成Integer类型

        本文链接:https://www.haomeiwen.com/subject/polcextx.html