Leading zeroes in the wrong end

beckindenmarkbeckindenmark Member Posts: 33
Hi
I need to export some fields in fixed length and I need to add zeros in beginning of the data.
This codeline works fine, result is 00004551, witch is correct
FORMAT("Sales Invoice Header"."Order No.",0,'<TEXT,8><Filler Character,0>');

But every field that contain amounts don't work, result 655000000, should be 000006500

f23 := FORMAT("Sales Invoice Line"."Unit Price",0,'<Precision,2:2><Standard Format,0>');
f23 := DELCHR(f23,'=',',');
f23 := DELCHR(f23,'=','.');
f23 := FORMAT(f23,0,'<TEXT,9><Filler Character,0>');

Is there anyone who could help a little bit, I tryed with PADSTR but same result.

Regards
Lars

Answers

  • David_SingletonDavid_Singleton Member Posts: 5,479
    Hi
    I need to export some fields in fixed length and I need to add zeros in beginning of the data.
    This codeline works fine, result is 00004551, witch is correct
    FORMAT("Sales Invoice Header"."Order No.",0,'<TEXT,8><Filler Character,0>');

    But every field that contain amounts don't work, result 655000000, should be 000006500

    f23 := FORMAT("Sales Invoice Line"."Unit Price",0,'<Precision,2:2><Standard Format,0>');
    f23 := DELCHR(f23,'=',',');
    f23 := DELCHR(f23,'=','.');
    f23 := FORMAT(f23,0,'<TEXT,9><Filler Character,0>');

    Is there anyone who could help a little bit, I tryed with PADSTR but same result.

    Regards
    Lars

    Assuming you want the number in pennies format (eg $376.92 - 000037692) then I would just multiply by 100, round to an integer, then assign the value as an integer in the function that you have that already works. I guess what is happening now is that the FORMAT is left justifying.
    MyNewIntegerValue := Round("Sales Invoice Line"."Unit Price" * 100,1);
    

    KISS.....
    David Singleton
  • DaveTDaveT Member Posts: 1,039
    Hi Lars,

    If you need the decimal point use
    Pricestr := FORMAT( "Unit Price", 10, '<integer,8><filler character,0><decimal,2>');
    
    or
    Pricestr := FORMAT( "Unit Price", 10, '<integer,8><filler character,0><decimal,2><filler character,0>');
    


    i.e. the "filler character" attribute relates to the preceeding attribute.

    hope this makes sence
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • kinekine Member Posts: 12,562
    in most cases I am solving that by own code like
    while StrLen(MyVar)<MySize do
      MyVar := FillerChar + MyVar;
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • krikikriki Member, Moderator Posts: 9,110
    how about this:
    txtString := PADSTR('',intMaxLen - STRLEN(txtString),txtFillerChar) + x;
    

    To be honest I don't really like looping to fill up a string like that :wink:
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • kinekine Member Posts: 12,562
    Yes, it looks like without loop, but I bet that inside the PADSTR there is a loop... 8)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • krikikriki Member, Moderator Posts: 9,110
    Probably yes, but it more performant :mrgreen:
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.