format(value, picture)The format function provides editting functions on values. It takes two arguments. The first is the value to be editted - value. If the second argument is omitted, format simply converts value to string. The second argument is a edit string describing the editting desired - picture. There are two types of pictures - string and numeric.
The picture string is scanned and each character - x or X, is is replaced by a character from the value string. Any other characters in the picture string are left unchanged. The value string is extended with spaces as needed.
Examples:
Expression Result
format('abc', 'x x x') 'a b c'
format('8005551212', '(XXX) XXX-XXXX') '(800) 555-1212'
format('xyz', '*x*x*x*x*') '*x*y*z* *'
A numeric picture string is scanned and each character - 9, is replaced by digit from the numeric value. Normally, other characters in the picture are left unchanged. If a decimal character (.) is found in the picture string, the digits of the numeric value are arranged around it, otherwise only the integral portion of the numeric value is used. The numeric value is extended on the left and right of the decimal character with zeros as needed.
Examples:
Expression Result format(12.34, '999.9') '012.3' format(12.34, '99.999') '12.340' format(12.34, '9,999') '0,012' format(.1234, '.9999') '.1234' format(12.34, '9.9999') '?.????'Note: As shown in the last example, signficance overflow is indicated by question mark characters.
Examples:
Expression Result format(12.34, '000.9') ' 12.3' format(12.34, '0,999') ' 012' format(.1234, '0,000.9999') ' .1234' format(.1234, '0,009.9999') ' 0.1234' format(10196, '09/09/09') ' 1/ 1/96'
The minus (-) character is not replaced when the numeric value is negative and is replaced by a space when the numeric value is zero or postive. The plus (+) character is not replaced when the numeric value is zero or postive and is replaced by a minus (-) character when the numeric value is negative. Examples:
Expression Result format(12.34, '0,000.99-') ' 12.34 ' format(-12.34, '0,000.99-') ' 12.34-' format(12.34, '0,000.99+') ' 12.34+' format(-12.34, '0,000.99+') ' 12.34-'
Parentheses may also be a leading sign. If a leading left parenthesis - (, is found, it is replaced by a space when the numeric value is zero or positive. When the leading left parenthesis is used, a trailing right parenthesis - ), is also replaced by a space when the numeric value is not negative.
Examples:
Expression Result format(12.34, '-0,000.99') ' 12.34' format(-12.34, '-0,000.99') '- 12.34' format(12.34, '+0,000.99') '+ 12.34' format(-12.34, '+0,000.99') '- 12.34' format(12.34, '(0,000.99)') ' 12.34 ' format(-12.34, '(0,000.99)') '( 12.34)'
The leftmost non-zero suppressed digit or the decimal place is preceded by the appropriate sign character. Sign floating is terminated by a 0, 9 or decimal character.
Examples:
Expression Result format(12.34, '--,---.99') ' 12.34' format(-12.34, '--,---.99') ' -12.34' format(12.34, '++,+++.99') ' +12.34' format(-12.34, '++,+++.99') ' -12.34' format(12.34, '((,(((.99)') ' 12.34 ' format(-12.34, '((,(((.99)') ' (12.34)'
Examples:
Expression Result format(12.34, '$$,$$$.99') ' $12.34' format(12.34, '**,***.99') '****12.34' format(12.34, '##,###.99') ' #12.34'
Examples:
Expression Result format(12.34, '$--,---.99') ' $12.34' format(-12.34, '$--,---.99') ' $-12.34' format(12.34, '*++,+++.99') '****+12.34' format(-12.34, '*++,+++.99') '****-12.34' format(12.34, '#((,(((.99)') ' #12.34 ' format(-12.34, '#((,(((.99)') ' #(12.34)'