Jquery parseInt - String to Integer
Converting a string to integer to perform arithmetical operations
var myString = '1234'; var myInteger; myInteger = parseInt(myString);
To convert a string to decimal:
var myString = '1234.098'; var myInteger = parseInt(myString); // result = 1234 var myNumber = parseFloat(myString); // result = 1234.098
To reduce the number of decimals:
var myNumber = 1234.098; myNumber = myNumber.toFixed(2); // result = 1234.09
Latest news
- - S5 Slide Show System: PowerPoint on Linux
- - µTorrent for Linux
- - Linux audio tagger
- - Gnome 3 release date - interview with Stormy Peters
- - Ubuntu Maverick Meerkat Beta Released
- - Ubuntu Maverick Meerkat frozen
- - Tab Candy for Firefox
- - Ubuntu font launched for beta testing
- - Interview with Richard Stallman
- - Linux Mint 9 KDE released
- - Gnome 3 release date delayed to march 2011
Comentarii
Sagar (28.04.2012)
Nice explanation! The parseInt() function has a syntax parseInt(string, radix). You might have to provide radix parameter sometimes to avoid few issues. Below is the post that explains this issue with its solution. http://swsharinginfo.blogspot.in/2011/09/jquery-parseint-without-radix-may-cause.html
Lauren (25.03.2011)
Needed to convert string to integer and parseInt did the trick!
george (13.08.2010)
I've searched and it doesn't seem to exist something jQuery specific
pedro (12.06.2010)
that's a standard jscript function,not a jquery function...