Possible Duplicate:
Behavior difference between parseInt() and parseFloat()
var box = $('.box'),
fontSize = parseInt(box.css('font-size'), 10) + 5;
$('button').on('click', function() {
box.animate({fontSize: fontSize});
});
//..
var box = $('.box'),
fontSize = parseFloat(box.css('font-size'), 10) + 5;
$('button').on('click', function() {
box.animate({fontSize: fontSize})
});
what the difference between..
**fontSize = parseInt(box.css('font-size'), 10);**
**fontSize = parseFloat(box.css('font-size'), 10);**
and and why should put 10 as a context..Please Help?
First of all only
parseInt
accepts second argument. It's called radix. It represents numeral system to be used. In example you can convert number into binary or hexadecimal code.parseFloat
only accepts one argument.Any number literal contained in a string is also converted correctly, so the string "0xA" is properly converted into the number 10. However, the string "22.5" will be converted to 22 , because the decimal point is an invalid character for an integer. Some examples:
The parseInt() method also has a radix mode, allowing you to convert strings in binary, octal, hexadecimal, or any other base into an integer. The radix is specified as a second argument to parseInt() , so a call to parse a hexadecimal value looks like this:
If decimal numbers contain a leading zero, it’s always best to specify the radix as 10 so that you won’t accidentally end up with an octal value. For example:
Another difference when using parseFloat() is that the string must represent a floating-point number in decimal form, not octal or hexadecimal. This method ignores leading zeros, so the octal number 0908 will be parsed into 908 , and the hexadecimal number 0xA will return NaN because x isn’t a valid character for a floating-point number. There is also no radix mode for parseFloat() .
Read More, Read More
Similar Question Read more here