Home

function: toSafeInteger


toSafeInteger(value: *): number

Converts `value` to a safe integer. A safe integer can be compared and represented correctly.

Example(s):

toSafeInteger(3.2)
// => 3

toSafeInteger(Number.MIN_VALUE)
// => 0

toSafeInteger(Infinity)
// => 9007199254740991

toSafeInteger('3.2')
// => 3

Params:

Name Type Attribute Description
value The value to convert.

Returns:

number

  {
    "comment": "/**\r\n * Converts `value` to a safe integer. A safe integer can be compared and\r\n * represented correctly.\r\n *\r\n * @since 4.0.0\r\n * @category Lang\r\n * @param {*} value The value to convert.\r\n * @returns {number} Returns the converted integer.\r\n * @example\r\n *\r\n * toSafeInteger(3.2)\r\n * // => 3\r\n *\r\n * toSafeInteger(Number.MIN_VALUE)\r\n * // => 0\r\n *\r\n * toSafeInteger(Infinity)\r\n * // => 9007199254740991\r\n *\r\n * toSafeInteger('3.2')\r\n * // => 3\r\n */",
    "meta": {
        "range": [
            598,
            874
        ],
        "filename": "toSafeInteger.js",
        "lineno": 28,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100010200",
            "name": "toSafeInteger",
            "type": "FunctionDeclaration",
            "paramnames": [
                "value"
            ]
        },
        "vars": {
            "value": "toSafeInteger~value"
        }
    },
    "description": "Converts `value` to a safe integer. A safe integer can be compared and\rrepresented correctly.",
    "since": "4.0.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "Lang",
            "value": "Lang"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "*"
                ]
            },
            "description": "The value to convert.",
            "name": "value"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "number"
                ]
            },
            "description": "Returns the converted integer."
        }
    ],
    "examples": [
        "toSafeInteger(3.2)\r// => 3\r\rtoSafeInteger(Number.MIN_VALUE)\r// => 0\r\rtoSafeInteger(Infinity)\r// => 9007199254740991\r\rtoSafeInteger('3.2')\r// => 3"
    ],
    "name": "toSafeInteger",
    "longname": "toSafeInteger",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000936",
    "___s": true,
    "filepath": "toSafeInteger.js"
}