I have some ArrayList and I want to convert the values of all element of those ArrayList into BigDecimal because double datatype produce unprecise result. I use temporary variable to store the result of the calculation the I assign the values of those temporary variable into the ArrayList. How do I get the precise value of singleSmoothing,doubleSmoothing, and 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);
}