The Wayback Machine - https://web.archive.org/web/20201220222506/https://github.com/lodash/lodash/blob/master/toInteger.js
Skip to content
Permalink
master
Go to file
 
 
Cannot retrieve contributors at this time
35 lines (32 sloc) 731 Bytes
import toFinite from './toFinite.js'
/**
* Converts `value` to an integer.
*
* **Note:** This method is loosely based on
* [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
*
* @since 4.0.0
* @category Lang
* @param {*} value The value to convert.
* @returns {number} Returns the converted integer.
* @see isInteger, isNumber, toNumber
* @example
*
* toInteger(3.2)
* // => 3
*
* toInteger(Number.MIN_VALUE)
* // => 0
*
* toInteger(Infinity)
* // => 1.7976931348623157e+308
*
* toInteger('3.2')
* // => 3
*/
function toInteger(value) {
const result = toFinite(value)
const remainder = result % 1
return remainder ? result - remainder : result
}
export default toInteger
You can’t perform that action at this time.