Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8979509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:51:49+00:00 2026-06-15T19:51:49+00:00

Possible Duplicate: Why parseInt() works like this? I have an issue with parseInt() returning

  • 0

Possible Duplicate:
Why parseInt() works like this?

I have an issue with parseInt() returning 0 unexpectedly, here’s a sample:

parseInt('-06') = -6
parseInt('-07') = -7
parseInt('-08') = 0

Why is the result 0? Same if I keep going down (-09, -10, ect). The format of the string comes from my framework so I need to deal with it. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:51:50+00:00Added an answer on June 15, 2026 at 7:51 pm

    You need to pass a radix parameter when you use parseInt

    parseInt('-08', 10);
    

    When you don’t, and when the string you’re parsing has a leading zero, parseInt produces different results depending on your browser. The most common issue is that the string will be treated as a base-8 number, which is what you’re seeing.

    That’s why this worked for ‘-06’ and ‘-07’—those are both valid base-8 numbers. Since ‘-08’ isn’t a valid base-8 number, the parse failed, and 0 was returned.

    From MDN

    radix

    An integer that represents the radix of the above mentioned
    string. While this parameter is optional, always specify it to
    eliminate reader confusion and to guarantee predictable behavior.
    Different implementations produce different results when a radix is
    not specified.


    Also note that you can use the unary + operator to convert these strings to numbers:

    ​var str = '-08';
    var num = +str;
    
    console.log(num);​​​
    
    //logs -8
    

    DEMO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Workarounds for JavaScript parseInt octal bug well i have this http://jsfiddle.net/gMDfk/1/ The
Possible Duplicate: Workarounds for JavaScript parseInt octal bug I have the following numbers: 01
Possible Duplicate: Workarounds for JavaScript parseInt octal bug Here's a jsfiddle that shows the
Possible Duplicate: Why does parseInt(“09”) return 0 but parseInt(“07”) return 7? I have a
Possible Duplicate: Workarounds for JavaScript parseInt octal bug Given this script: <script type=text/javascript> var
Possible Duplicate: execute a function only once i have this bit of code and
Possible Duplicate: Java Calendar Setting Incorrectly i have this code: GregorianCalendar cal = (GregorianCalendar)
Possible Duplicate: Operator overloading I am seeing this in a piece of sample code:
Possible Duplicate: JavaScript: why does parseInt(1/0, 19) return 18? Why does parseInt(1/0, 19) evaluate
Possible Duplicate: Workarounds for JavaScript parseInt octal bug Parsing a string using parseInt method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.