rounding-values
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i rounding-values

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

7.08 kB

Total Files

10

Last publish

Collaborators

  • ken20206