MCPcopy Create free account
hub / github.com/javascriptdata/danfojs / round

Method round

src/danfojs-base/shared/utils.ts:450–492  ·  view source on GitHub ↗

* Round elements of an array or array of arrays to specified dp * @param arr The Array to round * @param dp The number of dp to round to * @param isSeries Whether the array is of type Series or not

(arr: Array<number | number[]>, dp: number = 1, isSeries: boolean)

Source from the content-addressed store, hash-verified

448 * @param isSeries Whether the array is of type Series or not
449 */
450 round(arr: Array<number | number[]>, dp: number = 1, isSeries: boolean): ArrayType1D | ArrayType2D {
451 if (dp < 0) {
452 dp = 1;
453 }
454
455 if (isSeries) {
456 const newArr = [];
457 for (let i = 0; i < arr.length; i++) {
458 const ele = arr[i];
459 if (typeof ele == "number" && !isNaN(ele) && ele !== undefined && ele !== null) {
460 newArr.push(Number((ele).toFixed(dp)));
461 } else {
462 newArr.push(ele)
463 }
464 }
465 return newArr as ArrayType1D
466 } else {
467 const resultArr = [];
468 for (let i = 0; i < arr.length; i++) {
469 const innerVal = arr[i];
470 const newArr: Array<number> = [];
471 if (Array.isArray(innerVal)) {
472 for (let i = 0; i < innerVal.length; i++) {
473 const ele = innerVal[i];
474 if (typeof ele == "number" && !isNaN(ele) && ele !== undefined && ele !== null) {
475 newArr.push(Number((ele).toFixed(dp)));
476 } else {
477 newArr.push(ele)
478 }
479 }
480 resultArr.push(newArr);
481 } else {
482 if (typeof innerVal == "number" && !isNaN(innerVal) && innerVal !== undefined && innerVal !== null) {
483 newArr.push(Number((innerVal).toFixed(dp)));
484 } else {
485 newArr.push(innerVal)
486 }
487 }
488
489 }
490 return resultArr;
491 }
492 }
493
494 /**
495 * Checks if a func is a function

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected