简体   繁体   中英

Caused by java.lang.NumberFormatException: Invalid float: "∞"

I am looking into Fabric Crashlytics to see crashes that my app has, and found this one:

Caused by java.lang.NumberFormatException: Invalid float: "∞" at java.lang.StringToReal.invalidReal(StringToReal.java:63) at java.lang.StringToReal.initialParse(StringToReal.java:164) at java.lang.StringToReal.parseFloat(StringToReal.java:323) at java.lang.Float.parseFloat(Float.java:306)

Code

public static Float parseFloat(String value) {
    return Float.parseFloat(value.replace(",", "."));
}

Please help me understand it.

That's most likely a Float overflow.

If the Float is bigger than it can handle it returns infinity (this also happens dividing by 0). You should add a condition to check if the number is between -Float.MAX_VALUE and Float.MAX_VALUE (Float range goes from 1.40239846 x 10^-45 to 3.40282347 x 10^38)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM