如何将ArrayList double的所有元素的值转换为BigDecimal?

时间:2016-05-04 04:47:09

标签: java arraylist bigdecimal

我有一些ArrayList,我想将这些ArrayList的所有元素的值转换为BigDecimal,因为double数据类型会产生不准确的结果。我使用临时变量来存储计算结果,我将这些临时变量的值分配给ArrayList。如何获得singleSmoothing,doubleSmoothing和finalForecast的精确值?

ArrayList<Double> price = new ArrayList(); 
ArrayList<Double> singleSmoothing = new ArrayList();
ArrayList<Double> doubleSmoothing = new ArrayList();
ArrayList<Double> finalForecast = new ArrayList()
double temporarySingle,temporaryDouble,finalTemporary = 0;
double alpha , beta =0;

for(i = 1; i < price.size(); i++){

temporarySingle = alpha * price.get(i) + (1 - alpha) * (singleSmoothing.get(i-1)+doubleSmoothing.get(i-1));

temporaryDouble = beta * (temporarySingle - singleSmoothing.get(i-1)) + (1 beta) * doubleSmoothing.get(i-1) ;

singleSmoothing.add(temporarySingle);
doubleSmoothing.add(temporaryDouble);
finalTemporary = singleSmoothing.get(i) + doubleSmoothing.get(i);
finalForecast.add(finalTemporary);

}        

0 个答案:

没有答案