Home > Software design >  Convert List <double> to Double
Convert List <double> to Double

Time:05-09

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(_answers).cos;
}

I am using angles package from pub. I want to assign the _answers variable to Angle.degrees function, but this is throwing an error. Error: The argument type 'List' can't be assigned to the parameter type 'double'. can anyone help how to fix this?

CodePudding user response:

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 :)

CodePudding user response:

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);
}
  • Related