Freigeben über


TRANSFORM( ) Function

Returns a character string from an expression in a format determined by a format code.

TRANSFORM(eExpression, [cFormatCodes])

Return Values

Character

Parameters

  • eExpression
    Specifies the character, currency, date, or numeric expression to format.
  • cFormatCodes
    Specifies one or more format codes that determine how the expression is formatted. The following table lists the available format codes.
    Format Codes Description
    @B Left-justifies numeric data within the display region.
    @C CR is appended to positive currency or numeric values to indicate a credit.
    @D Date and DateTime values are converted to the current SET DATE format.
    @E Date and DateTime values are converted to a BRITISH date format.
    @L Pads numeric data with leading zeroes.
    @R The transformation uses a format mask. The mask characters are not stored to the transformed value. Use only with character or numeric data. Mask characters include:

    9 or #   Represents a character or number.

    !   Converts lower-case letters to upper-case letters.

    @T Leading and trailing spaces are trimmed from character values.
    @X DB is appended to negative currency or numeric values to indicate a debit.
    @Z If 0, currency or numeric values are converted to spaces.
    @( Encloses negative currency or numeric values in parentheses.
    @^ Converts currency or numeric values to scientific notation.
    @0 Converts numeric or currency values to their hexadecimal equivalents. The numeric or currency value must be positive and less than 4,294,967,296.
    @! Converts an entire character string to uppercase.
    @$ Adds the current currency symbol specified by SET CURRENCY to currency and numeric values. By default, the symbol is placed immediately before or after the value. However, the currency symbol and its placement (specified with SET CURRENCY), the separator character (specified with SET SEPARATOR) and the decimal character (specified with SET POINT) can all be changed.
    X Specifies the width of character values. For example, if cFormatCodes is 'XX', 2 characters are returned.
    Y Converts logical true (.T.) and false (.F.) values to Y and N, respectively.
    ! Converts a lowercase character to uppercase in the corresponding position in a character string.
    . Specifies the decimal point position in currency and numeric values.
    , Separates digits to the left of the decimal point in currency and numeric values.

If you omit cFormatCodes, Visual FoxPro performs a default transformation on eExpression. The following table describes the transformation performed for each data type eExpression can assume:

Data Type Transformation Description
Character No transformation is performed.
Currency Transformation is determined by the settings specified in the Regional tab of the Options dialog box.
Date A DTOC( ) transformation is performed on the date.
DateTime A TTOC( ) transformation is performed on the date time.
Logical Logical true (.T.) and false (.F.) values are transformed to the character strings ".T." and ".F." respectively.
Numeric (includes Double, Float, or Integer data types) Trailing zeros are removed from the decimal portion of a numeric value. If the numeric value is a whole number, a decimal point is not included in the transformed value (for example, 4.0 is transformed to 4). If the numeric value is less than one but greater than negative one, zero is included before the decimal point (for example, .4 is transformed to 0.4).
General "Gen" is returned if the general field contains an object; "gen" is returned if the general field doesn't contain an object.
Memo No transformation is performed.

Example

STORE 12.34 TO gnPrice
CLEAR
? TRANSFORM(gnPrice, '$$$$.99')  && Displays $12.34

See Also

DTOC( ) | TTOC( ) | InputMask Property