Java: Convert scientific notation to regular int

前端 未结 6 432
迷失自我
迷失自我 2020-12-06 10:23

How do I convert scientific notation to regular int For example: 1.23E2 I would like to convert it to 123

Thanks.

6条回答
  •  粉色の甜心
    2020-12-06 10:49

    Check out DecimalFormat.parse().

    Sample code:

    DecimalFormat df = new DecimalFormat();
    Number num = df.parse("1.23E2", new ParsePosition(0));
    int ans = num.intValue();
    System.out.println(ans); // This prints 123
    

提交回复
热议问题