Pre-Fill or Pad with Zeros

dohertykdohertyk Member Posts: 94
Hello all,

I am trying to do this the easiest way possible, I don't want to be re-inventing the wheel.

I have a decimal, like "-1,235.83" or "480.75"

For output, I would ultimately like to have

"000001235-" or "0000000480+"

There has to be an easier way other then me doing a whole pile of programming. I was looking at the FormatStr, but it wasn't going to happen for me. The best I've been able to get was

AmtDue := FORMAT(AmountDue[4],10, '<integer><sign>');

and I've tried other things like

AmtDue := FORMAT(AmountDue[4],10, '"00000;#####"<integer><sign>');

but the output is not at all what I would like to have happen. Any assistance would be very much appreciated as I can't seem to find anything to what I need in the C/Side Reference or even in many of the newsgroups that I've been reading about.

Thanks again in advance,

Kevin

Answers

  • ara3nara3n Member Posts: 9,258
    dec := 1235.83;
    text := DELCHR(format(dec,0,'<Integer,10><Filler,0><Decimal,3><sign>'),'=','.');
    if dec > 0 then
    text := text + '+';
    
    message(text);
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ara3nara3n Member Posts: 9,258
    Ops I reread your code and it looks like you don't want the decimal. So here is the change.
    dec := -1235.83;
    text := format(dec,0,'<Integer,10><Filler,0><sign>');
    if dec > 0 then
      text := text + '+';
    
    message(text);
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • dohertykdohertyk Member Posts: 94
    ara3n wrote:
    Ops I reread your code and it looks like you don't want the decimal. So here is the change.
    dec := -1235.83;
    text := format(dec,0,'<Integer,10><Filler,0><sign>');
    if dec > 0 then
      text := text + '+';
    
    message(text);
    

    Thank you very much for your reply Rashed, As a result I was able to achieve my desired output. I didn't exactly use your method, but what I did use was:

    AmtDue := FORMAT(AmountDue[4],10,'<Integer,9><Filler,0><sign>');

    I had to use Integer, 9 because Integer, 10 bumped the sign off the end of the string.

    The only problem I face now is that it doesn't always supply a sign. It just shows a sign when it is negative. And when I Stream 2 numbers side by side.. I would expect them to be

    000000001+000000002-

    but instead I get

    000000001__000000002-

    the "_" are to show that I end up with two blank spots. In the first blank spot I would like to have the "+" and where the second blank spot is I'd rather not have anything.. So that the numbers just run, one into the next.

    If you have any idea's on how to tackle this problem it would be very much appreciated.

    Thanks again for all your help so far.

    Kevin
  • ara3nara3n Member Posts: 9,258
    In my code I've added at bottom if decimal is greater than 0 then append '+' to the string. That would solve your issue.

    if dec > 0 then
    text := text + '+';
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • dohertykdohertyk Member Posts: 94
    ara3n wrote:
    In my code I've added at bottom if decimal is greater than 0 then append '+' to the string. That would solve your issue.

    if dec > 0 then
    text := text + '+';

    Thanks for the promptness of your reply.

    That was my mistake.. I missed that, Thanks..

    What do you think about taking away the gap in between numbers?
  • ara3nara3n Member Posts: 9,258
    I would need to see an example code on how you are streaming in the text variables. and why you are getting blank between the variables.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • dohertykdohertyk Member Posts: 94
    ara3n wrote:
    I would need to see an example code on how you are streaming in the text variables. and why you are getting blank between the variables.

    That was my mistake, it's been fixed now.
  • ara3nara3n Member Posts: 9,258
    Great. A solved Title of the thread would be great.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • dohertykdohertyk Member Posts: 94
    ara3n wrote:
    Great. A solved Title of the thread would be great.

    I was looking for that option, but I don't know how to do that. There's no button for me to press. If you could be kind enough to let me know how to do it. I would do it.
  • ara3nara3n Member Posts: 9,258
    you just go to the first message and click on edit and then change the title.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • dohertykdohertyk Member Posts: 94
    ara3n wrote:
    you just go to the first message and click on edit and then change the title.

    Thanks... I've now done that. I've got a few others messages to fix up as well.
Sign In or Register to comment.