java float 存储方式_java-解析以字符串形式存储的float会抛出异...

在相关的源代码中可以看到,该值将被修剪:

static FloatingDecimal.ASCIIToBinaryConverter readJavaFormatString(String arg) throws NumberFormatException {

boolean arg0 = false;

boolean arg1 = false;

try {

arg = arg.trim();

....

因此,在转换为floatValue之前将删除空格.

有关更多信息,请参见Float.class调用的FloatingDecimal源代码.

Integer.parseInt()不会修剪字符串值:

public static int parseInt(String arg, int arg0) throws NumberFormatException {

if (arg == null) {

throw new NumberFormatException("null");

} else if (arg0 < 2) {

throw new NumberFormatException("radix " + arg0 + " less than Character.MIN_RADIX");

} else if (arg0 > 36) {

throw new NumberFormatException("radix " + arg0 + " greater than Character.MAX_RADIX");

} else {

int arg1 = 0;

boolean arg2 = false;

int arg3 = 0;

int arg4 = arg.length();

int arg5 = -2147483647;

if (arg4 > 0) {

char arg8 = arg.charAt(0);

if (arg8 < 48) {

if (arg8 == 45) {

arg2 = true;

arg5 = MIN_VALUE;

} else if (arg8 != 43) {

throw NumberFormatException.forInputString(arg);

}

if (arg4 == 1) {

throw NumberFormatException.forInputString(arg);

}

++arg3;

}

int arg7;

for (int arg6 = arg5 / arg0; arg3 < arg4; arg1 -= arg7) {

arg7 = Character.digit(arg.charAt(arg3++), arg0);

if (arg7 < 0) {

throw NumberFormatException.forInputString(arg);

}

if (arg1 < arg6) {

throw NumberFormatException.forInputString(arg);

}

arg1 *= arg0;

if (arg1 < arg5 + arg7) {

throw NumberFormatException.forInputString(arg);

}

}

return arg2 ? arg1 : -arg1;

} else {

throw NumberFormatException.forInputString(arg);

}

}

}

那就是为什么你在那里得到一个例外

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值