To convert a list of strings to a list of floats in Dart, you can use the map()
function to iterate over each string in the list and parse it as a float using double.parse()
.
In this example,
stringList
.map()
function to iterate over each string in the list and parse it as a float using double.parse()
.void main() {
List<String> stringList = ["1.1", "2.2", "3.3", "4.4", "5.5"];
List<double> floatList = stringList.map((str) => double.parse(str)).toList();
print(floatList);
}
[1.1, 2.2, 3.3, 4.4, 5.5]
In this tutorial, we learned How to Convert a List of Strings to a List of Floats in Dart language with well detailed examples.