Java Math.pow() Rounding Error

后端 未结 4 1828
囚心锁ツ
囚心锁ツ 2021-01-25 14:24

I\'m having trouble with (what I suspect is) a rounding error.

I have a string, 0.686357E-01, which I\'m trying to convert to a double. I\'ve been able to s

4条回答
  •  日久生厌
    2021-01-25 14:38

    Floating point numbers do not have perfect precision. If that is an issue, use BigDecimal:

    String string = "0.686357E-01";
    BigDecimal number = new BigDecimal(string);
    System.out.println(number);
    

提交回复
热议问题