Unpredictability of the BigDecimal(double) constructor

前端 未结 6 2198
后悔当初
后悔当初 2020-12-01 18:27

I started using Sonar recently in a project, and i got a PMD rule broken about using the constructor new BigDecimal(double val). When i read the java documentat

6条回答
  •  萌比男神i
    2020-12-01 19:05

    Because if you already begin with a double value as data, you have already lost that precission. So not having it would force you to convert it to String for BigDecimal to convert it back.

    And also, maybe sometimes you just need that value.

提交回复
热议问题