main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
758 bytes
|
Rev | Line | |
---|
[d565449] | 1 | import toFinite from './toFinite.js';
|
---|
| 2 |
|
---|
| 3 | /**
|
---|
| 4 | * Converts `value` to an integer.
|
---|
| 5 | *
|
---|
| 6 | * **Note:** This method is loosely based on
|
---|
| 7 | * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
|
---|
| 8 | *
|
---|
| 9 | * @static
|
---|
| 10 | * @memberOf _
|
---|
| 11 | * @since 4.0.0
|
---|
| 12 | * @category Lang
|
---|
| 13 | * @param {*} value The value to convert.
|
---|
| 14 | * @returns {number} Returns the converted integer.
|
---|
| 15 | * @example
|
---|
| 16 | *
|
---|
| 17 | * _.toInteger(3.2);
|
---|
| 18 | * // => 3
|
---|
| 19 | *
|
---|
| 20 | * _.toInteger(Number.MIN_VALUE);
|
---|
| 21 | * // => 0
|
---|
| 22 | *
|
---|
| 23 | * _.toInteger(Infinity);
|
---|
| 24 | * // => 1.7976931348623157e+308
|
---|
| 25 | *
|
---|
| 26 | * _.toInteger('3.2');
|
---|
| 27 | * // => 3
|
---|
| 28 | */
|
---|
| 29 | function toInteger(value) {
|
---|
| 30 | var result = toFinite(value),
|
---|
| 31 | remainder = result % 1;
|
---|
| 32 |
|
---|
| 33 | return result === result ? (remainder ? result - remainder : result) : 0;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | export default toInteger;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.