Tutorial on FORMAT function and property?

girish.joshigirish.joshi Member Posts: 407
Is there anywhere that I can get a really complete description of what the FORMAT function and property can do? The help file seems like a good start, but isn't really comprehensive.

In particular, my problem is I have a decimal field, and I want it formatted to a fixed length, with leading zeros, and an implied decimal point. I could code this from scratch, but it seems like a good opportunity to learn the Navision tools better.

Thanks for taking a look,

Girish Joshi

Comments

  • SavatageSavatage Member Posts: 7,142
    so you're trying to make

    1.29
    100.50
    20.39

    appear like

    0000129
    0010050
    0002039

    am I correct?
  • girish.joshigirish.joshi Member Posts: 407
    Yeah that's right. I would also add that I'm trying to make

    1

    appear as

    0000100

    And the real key for me would be to do it with as much of the navision standard library as possible.

    Thanks Savatage
  • SavatageSavatage Member Posts: 7,142
    Read these maybe they can help you....

    Initalizing a string to certain characters
    http://www.mibuso.com/forum/viewtopic.php?t=8157

    leading zeros for decimals
    http://www.mibuso.com/forum/viewtopic.php?t=7807

    *of couse if you multiply your # by 100 first that rids the decimal :lol:
  • girish.joshigirish.joshi Member Posts: 407
    Thanks again, Savatage.

    I did know how to accomplish the task using padstr etc, but what I was really hoping for was to be able to accomplish the task with format. From the help files, I get the impression that its very powerful, but there isn't enough information there for me to really know how to use it.
  • ara3nara3n Member Posts: 9,257
    dec is of type decimal
    dec := 1;

    DELCHR(format(dec,0,'<Integer,5><Filler,0><Decimal,3>'),'=','.')


    result is 0000100
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • girish.joshigirish.joshi Member Posts: 407
    wow. exactly what I was looking for.
  • girish.joshigirish.joshi Member Posts: 407
    This particular problem, decimals being converted into strings with implied decimal points and padding leading zeros, comes up frequently during integrations.

    I think ara3n's approach is the best here -- uses Navision code and is concise.

    Savatage's solution requires code for you to special case '0'. That is to say, multiplying by 100 to get rid of the decimals (to implement the implied point) isn't a good because if your value is 0, then 0*100=0 and it doesn't work.

    The WORST, god help you if you do, solution is to code your own parsing routing.
Sign In or Register to comment.