Convert a string value into an int

This question already has an answer here:

  • How do I convert a String to an int in Java? 30 answers
  • How to do an Integer.parseInt() for a decimal number? 9 answers

  • What about:

    int i = (int) Double.parseDouble(s);
    

    Of course, "20.00" is not in a valid integer format.


    String s = "20.00";

    is not valid Integer value that is the reason its throwing NumberFormatException .

    Format your number using either Double or Float then using narrow casting cast you number to int but you may loose precision if exists.

    ie int I = (int) Double.parseDouble(str);

    链接地址: http://www.djcxy.com/p/20916.html

    上一篇: “字符串不能转换为int”

    下一篇: 将字符串值转换为int