I need to convert decimal to text without losing any trailing zeroes at the end of the decimal. I tried using FORMAT but does not seem to work. I need to do this for a report so that the decimal point allignment will be ok if the number of decimals printed is always the same. I know that I can print the decimal value itself, but for some complex reasons I need to use Text type to print. Example: FORMAT(1.20,10, 0) displays 1.2 instead of 1.20. I also tried, FORMAT(1.20,10, 1), FORMAT(1.20,10, 2), etc. The following values should print as: 1.20 1.23 1.00 Any help will be much appreciated.

Use something like this: FORMAT(MyDecimalValue,7,’<Integer Thousand,3><Decimals,3>’); // Decimals X will force X-1 decimals to appear You’ll find how to build your own FORMAT in the help section of the FORMAT function. Use the font Courrier if you have problems of alignment.

[FORMAT(MyDecimalValue,7,’<Integer Thousand,3><Decimals,3>’); // Decimals X will force X-1 decimals to appear Thanks David. I do not understand the above. I tried looking at the help for FORMAT. It doesn’t seem to be clearly explained. I tried a couple of things but get compilation error. I would appreciate if you can give an example? Maybe use the examples that I used in my original post? thanks. Pari Somasundaram

Hi Pari, Try the following code in a codeunit. You can play with the numbers in the format function to force more decimals, etc. `OnRun() ShowDecimals; ShowDecimals() // VARIABLES to declare // Dec : Decimal (6 dimensions) // i : Integer // TextDisplay : Text 1024 Dec[1] := 1.2; Dec[2] := 1.23; Dec[3] := 1; Dec[4] := 3; Dec[5] := 3.4; Dec[6] := 3.42; FOR i := 1 TO 6 DO BEGIN TextDisplay := TextDisplay + FORMAT(Dec[i],7,'<Integer Thousand,3><Decimals,3>') + '\'; END; MESSAGE(TextDisplay);`

David, when I try FORMAT(-23.95,7,’<Integer Thousand,3><Decimals,3>’) it displays/prints as 23.95. I need the sign to display/print as well if the number is negative. How do I do this? Thanks. Pari

Paris, Just add a paramter at the beginning of the format string: // VARIABLES to declare // Dec : Decimal (6 dimensions) // i : Integer // TextDisplay : Text 1024 dec[1] := -23.95; dec[2] := 1.23; dec[3] := 1; dec[4] := 3; dec[5] := 3.4; dec[6] := 3.42; FOR i := 1 TO 6 DO BEGIN textdisplay := textdisplay + FORMAT(dec[i],7,’<Integer Thousand,3><Decimals,3>’) + ‘’; END; MESSAGE(textdisplay);

quote:

textdisplay := textdisplay + FORMAT(dec[i],7,‘<Integer Thousand~~,3~~><Decimals,3>’) + '';

Why the “,3” in IntegerThousand? `FORMAT(dec[i],20,'<sign><Integer Thousand]><Decimals,3>')`

looks better to me…

Thanks. Pari

…or this one: TextDisplay += FORMAT(Dec[i],7,’<precision,2>’) + ‘’; “Precision” is the same and takes same parameters as [e.g. form]property DecimalPlaces.

Hi David,

This is good code for Convert decimal into string with its decimalplaces