Monday, January 5, 2015

FORMAT Function (Code, Text)

Most of the time, we are using the function "FORMAT()" to convert values into string.

String := FORMAT(Value[, Length][, FormatStr/FormatNumber])

Parameters

Value
Type: Any
This is a C/AL variable (expression) of any simple data type, such as option, integer, biginteger, decimal, char, text, code, date, time, datetime, Boolean, binary, or GUID.
If, when the system formats Value, the result is a value larger than the maximum length MAXSTRLEN Function (Code, Text) of String, a run-time error occurs.
Length
Type: Integer
This optional parameter specifies the length of String. The following rules apply:
  • If Length = 0 then the entire value is returned (default).
  • If Length > 0 then the returned string will be exactly Length characters.
    If Value is less than Length characters, then either leading or trailing spaces are inserted, depending on the format that you select.
    If Value exceeds Length characters, then String is truncated to Length characters.
  • If Length < 0 then the returned string will not have leading or trailing spaces.
    If Value is less than Length characters, the length of String will equal the length of Value.
    If Value exceeds Length characters, then String is truncated to Length characters.
FormatStr
Type: String
A literal string that defines a format as in the Format Property.
For an example if we need,
Value (Decimal) := 22; Result (Text)
This will return on 22.
but think if we need to get the output like "22.00" ?
by using FORMAT() function is much easy.
Result := format(Value,0,'<Integer><Decimals,3>'); -> 22,00
Thank you.

Regaerds,
Dinuka.

No comments:

Post a Comment