rounding-values

Rounding the numbers in object and objects in array. Reference to camelcase-keys.

Usage no npm install needed!

<script type="module">
  import roundingValues from 'https://cdn.skypack.dev/rounding-values';
</script>

README

rounding-values

Rounding the numbers in object and objects in array. Reference to camelcase-keys.

Install

$ npm install --save rounding-values

Usage

"use strict";
const roundingValues = require("rounding-values");

const obj = { a: 1.2345 };
roundingValues(obj);
/*
    {
        "a": 1.23
    }
*/
const arr = [{ a: 1.2345, b: "1.2345" }];
roundingValues(obj, { decimal: 3 });
/*
    [
        {
            "a": 1.235,
            "b": "1.2345"
        }
    ]
*/
const innerArr = [{ a: 1.2345, b: "1.2345", c: [{ a: 1.2345, b: "1.2345" }, { a: 1.2345, b: "1.2345" }] }];
roundingValues(innerArr, { decimal: 3, deep: true });
/*
    [
        {
            "a": 1.235,
            "b": "1.2345",
            "c": [
                {
                    "a": 1.235,
                    "b": "1.2345"
                },
                {
                    "a": 1.235,
                    "b": "1.2345"
                }
            ]
        }
    ]
*/

API

roundingValues(input, options?)

input

Type: object | object[]

An object or array of objects.

options

Type: object

decimal

Type: number
Default: 2

Number of decimal to rounding

deep

Type: boolean
Default: false

Recurse nested objects and objects in arrays.