'Convert List <double> to Double

I want to convert the double type of list into a double variable, my code is something like this...

var _first=<double> [108,105,90.833,87.7,88.6];
     var _answers=<double>[];
     for (var i=0; i<_first.length;i++){
       _answers.add(_first[i]);
       double _cosa = Angle.degrees(_first[i]).cos;
       print(_cosa);
       print(_cosa[0]);
double a=_cosa[0];
double b=_cosa[1];
double c=_cosa[2];
double d=_cosa[3];
double e=_cosa[4];
}

_cosa variable printing 5 answers e.g: 1,2,3,4,5. I want to get all answers in 5 different variables. but this method throws an error.



Solution 1:[1]

This should be your updated code

var _first=<double> [108,105,90.833,87.7,88.6];
var _answers=<double>[];

for (var i=0; i<_first.length;i++){
  _answers.add(_first[i]);
  double _cosa = Angle.degrees(_first[i]).cos;  ///<-- updated
}

the problem was that you were passing a list of numbers to a parameter/input that receives a number value, here i.e double.

We know that CosA is found for angle, i.e a single value not a list of values.

Hope this helps. Upvote if it did :)

Solution 2:[2]

It appears that what you're trying to do is:

var _first=<double> [108,105,90.833,87.7,88.6];
var _answers=<double>[];

for (var i=0; i<_first.length;i++){
  _answers.add(Angle.degrees(_first[i]).cos);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Delwinn
Solution 2 Bob Jarvis - Слава Україні