Today I had a classic encounter with the FORMAT command in C/AL.
One of my colleagues was busy generating an ASCII file from NAV in which he wanted to make sure a decimal value was formatted with a two digit precision. (ie. 1.1 should be formatted as 1.10). He asked if I knew a format string for it.
My first reaction was to try the next syntax.
FORMAT(MyDecimal, 0, '<Integer><Decimals,2>');
But the result of this code I got '1.1' as a result. At the same moment I found myself stepping into a classic programming error because NAV counts the decimal separator as one of the characters for the decimals! So by using the next code, you will get the right result (in this case: '1.10').
FORMAT(MyDecimal, 0, '<Integer><Decimals,3>');
Since this is not the most intuitive thing to do, keep paying attention when formatting variables!
Thanks for your information...
Sorry for delay. But here it is.
MESSAGE(FORMAT(3.123, 0, '<Precision,4:4><Integer><Decimals>'))
It seems, that 'Precision' have to be first.
Thanks for the tip, but I tried that one and it doesn't seem to work, at least not in in NAV2009 R2.
Do you have a complete example?
You should use <Precision,2:2> to "force" NAV to return 2 decimal places.