dec-int
v3.0.1
Published
Get a base-10 integer from a NumericString or Number.
Downloads
2
Readme
dec-int
Returns a base-10 integer from a NumericString or Number. Returns NaN
if input
can't be coerced
to an integer.
decInt('56') // => 56
What is a NumericString?
Anything that would be a number if it didn't have quotes around it. For example, these are all numeric strings:
'5' or "5"
'123.456' or "123.456"
'-0' or "-0"
'0xFFFFFF' or "0xFFFFFF"
'020' or "020"
However, these are examples of what's not a NumericString:
"Infinity"
"Math.PI"
"PI"
"e"
Note: any input that is equivalent to negative-zero (except negative-zero itself) will evaluate to positive-zero. For example:
decInt(0); // => 0
decInt(-0); // => -0
decInt('-0'); // => 0
decInt('-0.5'); // => 0