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 6387405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:08:53+00:00 2026-05-25T03:08:53+00:00

Ok I have the following script: var text = ’24 – 08′; var value

  • 0

Ok I have the following “script”:

var text = '24 - 08';
var value = text.split(" - ");


var result = 24 - value[0];
result = result + value[1];
alert(result);

http://jsbin.com/amusaw/edit#javascript,html

So the result of this simple math thing is 0 with parseInt or 008 without it. It should be 8.
I tried this with several different numbers (instead of 08, 04 or 05 etc…)
or 22 – 09.

Sometimes the result value is right and sometimes it’s not.
I tried to apply parseInt to all “math operations” … no success.
I think it’s a tiny error, but I don’t get it 🙁

  • 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-05-25T03:08:54+00:00Added an answer on May 25, 2026 at 3:08 am

    Make sure you specify the base when parsing ints:

    parseInt(value[0], 10);
    parseInt(value[1], 10);
    

    Whole code:

    var text = '24 - 08';
    var value = text.split(" - ");
    
    
    var result = 24 - parseInt(value[0], 10);
    result = result + parseInt(value[1], 10);
    alert(result);
    

    http://jsbin.com/amusaw/2/edit

    When an string begins with a 0 parseInt assumes the number is octal (base 8). It’s deprecated behaviour, but it is the way it behaves at any rate. The number 08 is invalid in octal since only the digits 0-7 exist, so it just returns 0. It determines that the 8 isn’t part of the number, it is just like seeing 0A or 0T (or any other non 0-7 character).

    More on parseInt(): https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/parseInt. In fact you can find the parseInt("08"); example that caused the problem for you right near the bottom of that page.

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

Sidebar

Related Questions

I have the following script from http://javascript.about.com/library/bljver.htm <script type=text/javascript> var jsver = 1.0; </script>
UPDATE : I have the following code: <script type=text/javascript> function addScript(url) { var script
I have the following script: $(#border-radius).click(function(){ var value = $(#border-radius).attr(value); $(div.editable).click(function () { mySQLinsert(value,
I have following page <html> <head> <script type=text/javascript src=e01.js></script> </head> <body> <script type=text/javascript> var
I have the following script that changes my image on a timer: var da
Hi I have the following script in my form function pdf() { var frm
I have the following script: Timer=0; function countdown(auctionid){ var auctions; var divs; Timer=Timer+1; if((Timer%10==0)||(Timer==1)){
I have put together the following mootools script window.addEvent('domready', function() { var shouts =
I have the following: $(document).ready(function() { var myIframe = document.getElementById('myIframe'); var element = myIframe.contentDocument.createElement('script');
I have the following MXML: <mx:Script> var someBoolean:Boolean = determineSomeCondition(); </mx:Script> .... <foo:MyComponent somePropertyExpectingIDataRenderer={

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.