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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:32:59+00:00 2026-05-23T22:32:59+00:00

Possible Duplicate: Truncate leading zeros of a string in Javascript What is the simplest

  • 0

Possible Duplicate:
Truncate leading zeros of a string in Javascript

What is the simplest and cross-browser compatible way to remove leading zeros from a number in Javascript ?

e.g. If I have a textbox value as 014 or 065, it should only return 14 or 65

  • 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-23T22:33:00+00:00Added an answer on May 23, 2026 at 10:33 pm

    We can use four methods for this conversion

    1. parseInt with radix 10
    2. Number Constructor
    3. Unary Plus Operator
    4. Using mathematical functions (subtraction)
    const numString = "065";
    
    //parseInt with radix=10
    let number = parseInt(numString, 10);
    console.log(number);
    
    // Number constructor
    number = Number(numString);
    console.log(number);
    
    // unary plus operator
    number = +numString;
    console.log(number);
    
    // conversion using mathematical function (subtraction)
    number = numString - 0;
    console.log(number);

    Update(based on comments): Why doesn’t this work on “large numbers”?

    For the primitive type Number, the safest max value is 253-1(Number.MAX_SAFE_INTEGER).

    console.log(Number.MAX_SAFE_INTEGER);

    Now, lets consider the number string ‘099999999999999999999’ and try to convert it using the above methods

    const numString = '099999999999999999999';
    
    let parsedNumber = parseInt(numString, 10);
    console.log(`parseInt(radix=10) result: ${parsedNumber}`);
    
    parsedNumber = Number(numString);
    console.log(`Number conversion result: ${parsedNumber}`);
    
    parsedNumber = +numString;
    console.log(`Appending Unary plus operator result: ${parsedNumber}`);
    
    parsedNumber = numString - 0;
    console.log(`Subtracting zero conversion result: ${parsedNumber}`);

    All results will be incorrect.

    That’s because, when converted, the numString value is greater than Number.MAX_SAFE_INTEGER. i.e.,

    99999999999999999999 > 9007199254740991
    

    This means all operation performed with the assumption that the stringcan be converted to number type fails.

    For numbers greater than 253, primitive BigInt has been added recently. Check browser compatibility of BigInthere.

    The conversion code will be like this.

    const numString = '099999999999999999999';
    const number = BigInt(numString);
    

    P.S: Why radix is important for parseInt?

    If radix is undefined or 0 (or absent), JavaScript assumes the following:

    • If the input string begins with “0x” or “0X”, radix is 16 (hexadecimal) and the remainder of the string is parsed
    • If the input string begins with “0”, radix is eight (octal) or 10 (decimal)
    • If the input string begins with any other value, the radix is 10 (decimal)

    Exactly which radix is chosen is implementation-dependent. ECMAScript 5 specifies that 10 (decimal) is used, but not all browsers support this yet.

    For this reason, always specify a radix when using parseInt

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

Sidebar

Related Questions

Possible Duplicate: How to Truncate a string in PHP to the word closest to
Possible Duplicate: How to remove an XmlNode from XmlNodeList Hi, How can i delete
Possible Duplicate: .NET - What’s the best way to implement a catch all exceptions
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} What's the
Possible Duplicate: Singleton: How should it be used Following on from Ewan Makepeace 's
Possible Duplicate: Truncate all tables in a MySQL database in one command? I need
Possible Duplicate: Parse string into argv/argc I'm trying to write a fake shell using
Possible Duplicate: Updating progress dialog in Activity from AsyncTask I am developing my first
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should

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.