Keyboard Face

when you find QWERTY imprinted on your cheek - it's time to go to bed.

Tags

asp CSS css menus dreamweaver flash gallery2 hosting iis7 Javascript jquery jquery ui left mac mssql os9 php printer rdp SEO sql sql server windows wordpress

Javascript String to Int

April 4, 2006 by Tom 12 Comments

Handy function:

var yourInt;
yourInt = parseInt(str);

More Info: http://www.devguru.com/Technologies/ecmascript/quickref/parseint.html

Filed Under: Javascript

Comments

  1. dav7 says

    May 20, 2007 at 2:05 am

    Wow, thanks for that. First hit in Google and exact result to my problem (“start = parseInt(document.getElementById(‘text’).value);”).

    My function was returning an array with missing values when I tried to access `start – 1′ but as soon as I parseInt’ed it all was well \o/ 😀

    -dav7

  2. Scott says

    May 20, 2007 at 7:15 pm

    Perfect, thanks! I was lamenting having to use eval(), so this is perfect!

  3. Airor says

    October 5, 2007 at 10:31 am

    Instead I use the built in typecasting
    myInt = 0 + str;
    myStr = ” + i + ‘ number of things.’;

  4. Leonardo says

    January 22, 2008 at 1:42 pm

    Nice one,
    tkx

  5. johnsmith says

    July 10, 2008 at 1:36 pm

    Ja pierdole ale niemoc pisać tak zjebane artykuły.

    Nice 🙂

  6. norma savage says

    July 15, 2008 at 3:40 pm

    thanks!
    🙂

  7. Barnaby says

    September 13, 2008 at 8:28 am

    haha, to jest całkiem bez sensu artykuł

    Pretty cool, thanks 🙂

  8. Luong Xuan Thuy says

    September 26, 2008 at 2:40 am

    ———————————–
    var yourInt;
    yourInt = parseInt(str);
    ———————————–

    You can not use this code fragment if your string is “009”. parseInt(“099”)=0;
    Because “000” not is a octal digits.

    Thanks.

  9. Luong Xuan Thuy says

    September 26, 2008 at 2:40 am

    Sorry, I mean : Because “099″ not is a octal digits.

  10. Istvan says

    October 23, 2008 at 4:45 am

    You should always explicitly specify the radix to be safe:

    var yourInt;

    yourInt = parseInt(str,10);

    In this case you won’t have problems with strings that can be interpreted as octal numbers.

    From the javascript specification:

    If the radix parameter is omitted, JavaScript assumes the following:

    If the string begins with “0x”, the radix is 16 (hexadecimal)

    If the string begins with “0”, the radix is 8 (octal). This feature is deprecated

    If the string begins with any other value, the radix is 10 (decimal)

    Not all browsers implement the specification in the same way, so if you want your code to work consistently everywhere you shouldn’t omit the radix.

  11. brandonh says

    November 22, 2008 at 2:56 pm

    thank you so much lstvan. i was kicking myself trying to see why 08 was returning 0. you rule.

  12. I&Mdesign says

    December 4, 2008 at 9:34 am

    Thanks a lot for your explanation about hexadecimal and octal numbers espesially. It works!

Leave a Reply Cancel reply

Your email address will not be published.

Pages

  • About Me
  • WordPress Permalinks in IIS using Custom 404 Redirect

Archives

  • May 2019
  • February 2019
  • January 2018
  • May 2016
  • April 2016
  • December 2015
  • November 2015
  • May 2015
  • April 2015
  • January 2013
  • March 2012
  • February 2012
  • December 2011
  • September 2011
  • August 2011
  • November 2010
  • October 2010
  • June 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • September 2009
  • August 2009
  • July 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • November 2008
  • September 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • December 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • January 2007
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • May 2005

ASP.NET Resources

  • Keven Roth’s Code Library
  • Lemon Law

Blogroll

  • Arin Morfopoulos
  • Jamie
  • Physical Therapists

Code Search Engines

  • Koders
  • Krugle

CSS & Design Resources

  • CSS Basics

Other

  • Amazon
  • Car Repair Questions
  • Cool Quizzes
  • Delphi LA
  • Physical Therapy Clinic Directory
  • Quickbooks Questions
  • Secret Santa Game

Site\'s I\'ve Designed or Helped With

  • Area Rugs
  • Dental Implants
  • Dental Website Design
  • FHA Loans
  • Secret Santa Gift Ideas