web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CRM - JS - String to number converison

(0) ShareShare
ReportReport
Posted on by

I'm retrieving a string which would be along the lines of ISS00001
I want to trim the ISS and convert the string to a number
Then I want to add 1 to the number and covert back to string and add ISS back to it
However when I convert to string I lose all the 0's, does anyone know how to keep the 0's
the code is as follows;

var replaceIS = issueNum.replace("ISS","");
var issueInt = new Number(replaceIS);
issueInt++;

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    You have to pad it with 0's string in the front.

    take a look at this, might help you in what you are looking for

    stackoverflow.com/.../how-to-output-integers-with-leading-zeros-in-javascript

  • Verified answer
    Royal King Profile Picture
    27,686 on at

    Something like below will do the job... I have not tested this so check it 

    var replaceIS = issueNum.replace("ISS","");

    var strLth = replaceIS .length;  //store the length of the string after replacing ISS

    var issueInt = new Number(replaceIS);

    issueInt++;

    var hashStore = '000000000000000000000000000'; //Zero 
    
    var strwithLeadingZero= hashStore.substring(0,strLth-issueInt.length ) + issueInt; //Adds number of zeros based on returned number. 

  • Mahadeo Matre Profile Picture
    17,021 on at

    Try this.. 

    var reissue=issueNum.substring(3,issueNum.length);
    
    var newNumber=parseInt(reissue)+1;
    var issueNewNum='ISS';
    
    if(newNumber<99)
       issueNewNum=issueNewNum+'0000'+newNumber  
    if(newNumber<999 && newNumber>99)
      issueNewNum=issueNewNum+'000'+newNumber
    if(newNumber<9999 && newNumber>999)
      issueNewNum=issueNewNum+'00'+newNumber
    if(newNumber<99999 && newNumber>9999)
      issueNewNum=issueNewNum+'0'+newNumber
    if(newNumber<999999 && newNumber>99999)
      issueNewNum=issueNewNum+''+newNumber


  • Community Member Profile Picture
    on at

    More about String to Integer in Javascript......

    www.corelangs.com/.../parseint.html

    Biden

  • Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi Sjharrison

    Could you please define me What is isNum? I have similar problem and I need to use your solution.

    Thank you

    Regards,

    AW

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans