The JavaScript function parseInt
can be used to force conversion of a given parameter to an integer, whether that parameter is a string, float number, number, etc.
The function parseInt
indeed expects a string
in its first argument. Please check the documentation. Usually you can omit the second, radix
argument and then it will fall back to the default of 10
. But the safest is to always add the numeric system base as second argument (usually 10
).
If you'd like to cast a general value to number
, you can use the Number
function, like this.
var myNumber = Number(myGeneralValue);