www.webdeveloper.com
Results 1 to 5 of 5

Thread: How to Turn Off Conversion from Octal to Decimal in JavaScript

  1. #1
    Join Date
    Apr 2013
    Posts
    1

    Question How to Turn Off Conversion from Octal to Decimal in JavaScript

    Hello All,

    Please help me in stopping to convert from octal to decimal

    Code ::

    Code:
    getDetails(0106341417 );
    
    function getDetails(number)
    {
    alert(number); // getting 18465551 
    
    }
    please help me to stop converting the number into decimal and we are getting the number dynamically donoo when the number will start with '0' and when it wont start with '0'

    Thanks in Advnace,

    Ajay

  2. #2
    Join Date
    Feb 2006
    Posts
    2,927
    Use strings instead of numbers- you can alert(number.toString(8))

    to return 106341417 in most browsers, but it is an error in strict code,

    and no number except 0 in any base begins with a zero-

    the leading 0 is an octal escape, which is deprecated.

  3. #3
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,364

    Lightbulb

    Alternatively send it to the function as a string and remove the leading zeros.
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <title> Untitled </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    </head>
    <body>
    <script type="text/javascript">
    getDetails('0106341417');
    getDetails('0000106341417');
    
    function getDetails(number) {
      number = number.replace(/^[0]+/,'')
      alert(number); // should be 106341417 both times
    }
    </script>
    
    </body>
    </html>

  4. #4
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787

  5. #5
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    Simply use the parseInt('0106341417',10) methode with a string and the 10 base !
    Last edited by 007Julien; 04-05-2013 at 06:22 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles