round method
Rounds each element in the vector to the specified number of decimal places.
decimalPlaces: The number of decimal places to round to.
Returns a new vector with the rounded elements.
Example:
var vector = Vector([1.2345, 2.3456]);
var roundedVector = vector.round(3);
print(roundedMatrix);
// Output:
// 1.235 2.346
// 3.457 4.568
Implementation
Vector round([int decimalPlaces = 0]) {
// Create a new data structure for the rounded matrix
List newData = List.filled(
length, decimalPlaces == 0 ? Complex.zero() : Complex(0.0, 0.0));
// Iterate over each element in the matrix
for (int i = 0; i < length; i++) {
if (decimalPlaces == 0) {
newData[i] = _data[i].round();
} else {
newData[i] = (_data[i] * math.pow(Complex(10), decimalPlaces)).round() /
math.pow(Complex(10), decimalPlaces);
}
}
return Vector(newData);
}