Integer.parse(String str) java.lang.NumberFormatException: Errors

前端 未结 8 1582
一整个雨季
一整个雨季 2020-12-11 22:18

I keep getting number format expectations, even though I\'m trimming the strings and they don\'t contain non numerical characters bizarrely it works for some numbers and not

相关标签:
8条回答
  • 2020-12-11 23:11
        String n="3020857508";
        Long l = Long.parseLong(n.trim());
        System.out.println(l);
    

    Integer MAX_VALUE : 2147483647, Long MAX_VALUE : 9223372036854775807

    As string n will not fit in Integer after conversion we have to use Long.

    And if you are still not sure about range that can come in String. go with BigIntegerwhere number is held in an int[]

    0 讨论(0)
  • 2020-12-11 23:11

    In Java, the integer range is from -2,147,483,648 to 2,147,483,647 make sure your numeric value is between the same.

    0 讨论(0)
提交回复
热议问题