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 :

Zero Padding Numbers in D365 F&O x++

Rahul Kiran Profile Picture Rahul Kiran 481

 Sometimes we need to add padding numbers in the files in AX. Ex: Postive pay files

I found the below post that helped to add the padding zero numbers in the positive pay file.

Original post: http://www.atomicax.com/content/zero-padding-numbers


AX provides us with an easy way to pad strings with extra characters. A common situation where this is required is use a "fake" number sequence inside AX.
If you wish to increment a counter, but store or display it as a string such as "ABC-00001", "ABC-00002" etc then padding the counter with zeros is required.

We can use the strRFix() and strLFix() methods to achieve this.

static void testZeroPadding(Args _args)
{
int i = 1;
str padded;
str finalResult;
;
// Create a string, with a length of 5, ending with the value of i and padded with zeros
padded = strRFix(int2str(i), 5, "0");
finalResult = strFmt("ABC-%1", padded);

}

This will populate finalResult with ABC-00001. If we use strLFix instead of strRFix, it will pad to the right with zeros, giving us ABC-10000.

Alternatively, you could use a function like this: (However, the approach above is most likely faster)

static str zeroPad(str item, int numZero)
{
int i;
str out;
;
for(i=0;i<numZero-strlen(item); i++)
{
out += "0";
}

return(out + item);
}


This was originally posted here.

Comments

*This post is locked for comments