What is a good solution for calculating an average where the sum of all values exceeds a double's limits?

前端 未结 17 2206

I have a requirement to calculate the average of a very large set of doubles (10^9 values). The sum of the values exceeds the upper bound of a double, so does anyone know a

17条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 19:01

    Apart from using the better approaches already suggested, you can use BigDecimal to make your calculations. (Bear in mind it is immutable)

提交回复
热议问题