有些函数中要用到TFormatSettings类型的变量,比如DateTimeToStr()和FormatFloat(),代表数据格式的,但在不同的函数中,参数的格式不同,比如上面两个函数,前者是时间的格式,后者是单精度浮点数的格式,谁能详细说明一下各种数据类型的TFormatSettings类型的格式?
我在帮助中没找到。

解决方案 »

  1.   

    Format strings specify required formats to general-purpose formatting routines.DescriptionFormat strings passed to the string formatting routines contain two types of objects -- literal characters and format specifiers. Literal characters are copied verbatim to the resulting string. Format specifiers fetch arguments from the argument list and apply formatting to them.Format specifiers have the following form:"%" [index ":"] ["-"] [width] ["." prec] typeA format specifier begins with a % character. After the % come the following, in this order:An optional argument index specifier, [index ":"]
    An optional left justification indicator, ["-"]
    An optional width specifier, [width]
    An optional precision specifier, ["." prec]
    The conversion type character, typeThe following table summarizes the possible values for type:d Decimal. The argument must be an integer value. The value is converted to a string of decimal digits. If the format string contains a precision specifier, it indicates that the resulting string must contain at least the specified number of digits; if the value has less digits, the resulting string is left-padded with zeros.
    u Unsigned decimal. Similar to 'd' but no sign is output.
    e Scientific. The argument must be a floating-point value. The value is converted to a string of the form "-d.ddd...E+ddd". The resulting string starts with a minus sign if the number is negative. One digit always precedes the decimal point.The total number of digits in the resulting string (including the one before the decimal point) is given by the precision specifier in the format string梐 default precision of 15 is assumed if no precision specifier is present. The "E" exponent character in the resulting string is always followed by a plus or minus sign and at least three digits.
    f Fixed. The argument must be a floating-point value. The value is converted to a string of the form "-ddd.ddd...". The resulting string starts with a minus sign if the number is negative.The number of digits after the decimal point is given by the precision specifier in the format string梐 default of 2 decimal digits is assumed if no precision specifier is present.
    g General. The argument must be a floating-point value. The value is converted to the shortest possible decimal string using fixed or scientific format. The number of significant digits in the resulting string is given by the precision specifier in the format string梐 default precision of 15 is assumed if no precision specifier is present.Trailing zeros are removed from the resulting string, and a decimal point appears only if necessary. The resulting string uses fixed point format if the number of digits to the left of the decimal point in the value is less than or equal to the specified precision, and if the value is greater than or equal to 0.00001. Otherwise the resulting string uses scientific format.
    n Number. The argument must be a floating-point value. The value is converted to a string of the form "-d,ddd,ddd.ddd...". The "n" format corresponds to the "f" format, except that the resulting string contains thousand separators.
    m Money. The argument must be a floating-point value. The value is converted to a string that represents a currency amount. The conversion is controlled by the CurrencyString, CurrencyFormat, NegCurrFormat, ThousandSeparator, DecimalSeparator, and CurrencyDecimals global variables, all of which are initialized from the Currency Format in the International section of the Windows Control Panel. If the format string contains a precision specifier, it overrides the value given by the CurrencyDecimals global variable.
    p Pointer. The argument must be a pointer value. The value is converted to an 8 character string that represents the pointers value in hexadecimal.
    s String. The argument must be a character, a string, or a PChar value. The string or character is inserted in place of the format specifier. The precision specifier, if present in the format string, specifies the maximum length of the resulting string. If the argument is a string that is longer than this maximum, the string is truncated.
    x Hexadecimal. The argument must be an integer value. The value is converted to a string of hexadecimal digits. If the format string contains a precision specifier, it indicates that the resulting string must contain at least the specified number of digits; if the value has fewer digits, the resulting string is left-padded with zeros.
    Conversion characters may be specified in uppercase as well as in lowercase梑oth produce the same results.
    For all floating-point formats, the actual characters used as decimal and thousand separators are obtained from the DecimalSeparator and ThousandSeparator global variables.
    Index, width, and precision specifiers can be specified directly using decimal digit string (for example "%10d"), or indirectly using an asterisk character (for example "%*.*f"). When using an asterisk, the next argument in the argument list (which must be an integer value) becomes the value that is actually used. For example, Format('%*.*f', [8, 2, 123.456]) is the same as Format('%8.2f', [123.456]).
    A width specifier sets the minimum field width for a conversion. If the resulting string is shorter than the minimum field width, it is padded with blanks to increase the field width. The default is to right-justify the result by adding blanks in front of the value, but if the format specifier contains a left-justification indicator (a "-" character preceding the width specifier), the result is left-justified by adding blanks after the value.An index specifier sets the current argument list index to the specified value. The index of the first argument in the argument list is 0. Using index specifiers, it is possible to format the same argument multiple times. For example "Format('%d %d %0:d %1:d', [10, 20])" produces the string '10 20 10 20'.Note: Setting the index specifier affects all subsequent formatting. That is, Format('%d %d %d %0:d %d', [1, 2, 3, 4]) returns '1 2 3 1 2', not '1 2 3 1 4'. To get the latter result, you have must use  Format('%d %d %d %0:d %3:d', [1, 2, 3, 4])
      

  2.   

    Controls formatting of dates and times.DescriptionDate-Time Format Strings specify the formatting of date-time values (such as TDateTime) when they are converted to strings. Date Time Format Strings are passed to formatting methods and procedures (such as FormatDateTime), and are also used to set certain global variables (such as ShortDateFormat).Date Time Format Strings are composed from specifiers that represent values to be inserted into the formatted string. Some specifiers (such as "d"), simply format numbers or strings. Other specifiers (such as "/") refer to locale-specific strings from global variables.In the following table, specifiers are given in lower case. Case is ignored in formats, except for the "am/pm" and "a/p" specifiers.Specifier Displays
    c Displays the date using the format given by the ShortDateFormat global variable, followed by the time using the format given by the LongTimeFormat global variable. The time is not displayed if the date-time value indicates midnight precisely.
    d Displays the day as a number without a leading zero (1-31).
    dd Displays the day as a number with a leading zero (01-31).
    ddd Displays the day as an abbreviation (Sun-Sat) using the strings given by the ShortDayNames global variable.
    dddd Displays the day as a full name (Sunday-Saturday) using the strings given by the LongDayNames global variable.
    ddddd Displays the date using the format given by the ShortDateFormat global variable.
    dddddd Displays the date using the format given by the LongDateFormat global variable.
    e Displays the year in the current period/era as a number without a leading zero (Japanese, Korean and Taiwanese locales only).
    ee Displays the year in the current period/era as a number with a leading zero (Japanese, Korean and Taiwanese locales only).
    g Displays the period/era as an abbreviation (Japanese and Taiwanese locales only).
    gg Displays the period/era as a full name. (Japanese and Taiwanese locales only).
    m Displays the month as a number without a leading zero (1-12). If the m specifier immediately follows an h or hh specifier, the minute rather than the month is displayed.
    mm Displays the month as a number with a leading zero (01-12). If the mm specifier immediately follows an h or hh specifier, the minute rather than the month is displayed.
    mmm Displays the month as an abbreviation (Jan-Dec) using the strings given by the ShortMonthNames global variable.
    mmmm Displays the month as a full name (January-December) using the strings given by the LongMonthNames global variable.
    yy Displays the year as a two-digit number (00-99).
    yyyy Displays the year as a four-digit number (0000-9999).
    h Displays the hour without a leading zero (0-23).
    hh Displays the hour with a leading zero (00-23).
    n Displays the minute without a leading zero (0-59).
    nn Displays the minute with a leading zero (00-59).
    s Displays the second without a leading zero (0-59).
    ss Displays the second with a leading zero (00-59).
    z Displays the millisecond without a leading zero (0-999).
    zzz Displays the millisecond with a leading zero (000-999).
    t Displays the time using the format given by the ShortTimeFormat global variable.
    tt Displays the time using the format given by the LongTimeFormat global variable.
    am/pm Uses the 12-hour clock for the preceding h or hh specifier, and displays 'am' for any hour before noon, and 'pm' for any hour after noon. The am/pm specifier can use lower, upper, or mixed case, and the result is displayed accordingly.
    a/p Uses the 12-hour clock for the preceding h or hh specifier, and displays 'a' for any hour before noon, and 'p' for any hour after noon. The a/p specifier can use lower, upper, or mixed case, and the result is displayed accordingly.
    ampm Uses the 12-hour clock for the preceding h or hh specifier, and displays the contents of the TimeAMString global variable for any hour before noon, and the contents of the TimePMString global variable for any hour after noon.
    / Displays the date separator character given by the DateSeparator global variable.
    : Displays the time separator character given by the TimeSeparator global variable.
    'xx'/"xx" Characters enclosed in single or double quotes are displayed as-is, and do not affect formatting.
      

  3.   

    Formats a floating point value.UnitSysUtilsCategoryfloating point conversion routinesfunction FormatFloat(const Format: string; Value: Extended): string;DescriptionFormatFloat formats the floating-point value given by Value using the format string given by Format. The following format specifiers are supported in the format string:Specifier Represents
    0 Digit place holder. If the value being formatted has a digit in the position where the '0' appears in the format string, then that digit is copied to the output string. Otherwise, a '0' is stored in that position in the output string.
    # Digit placeholder. If the value being formatted has a digit in the position where the '#' appears in the format string, then that digit is copied to the output string. Otherwise, nothing is stored in that position in the output string.
    . Decimal point. The first '.' character in the format string determines the location of the decimal separator in the formatted value; any additional '.' characters are ignored. The actual character used as a the decimal separator in the output string is determined by the DecimalSeparator global variable. The default value of DecimalSeparator is specified in the Number Format of the International section in the Windows Control Panel.
    , Thousand separator. If the format string contains one or more ',' characters, the output will have thousand separators inserted between each group of three digits to the left of the decimal point. The placement and number of ',' characters in the format string does not affect the output, except to indicate that thousand separators are wanted. The actual character used as a the thousand separator in the output is determined by the ThousandSeparator global variable. The default value of ThousandSeparator is specified in the Number Format of the International section in the Windows Control Panel.
    E+ Scientific notation. If any of the strings 'E+', 'E-', 'e+', or 'e-' are contained in the format string, the number is formatted using scientific notation. A group of up to four '0' characters can immediately follow the 'E+', 'E-', 'e+', or 'e-' to determine the minimum number of digits in the exponent. The 'E+' and 'e+' formats cause a plus sign to be output for positive exponents and a minus sign to be output for negative exponents. The 'E-' and 'e-' formats output a sign character only for negative exponents.
    'xx'/"xx" Characters enclosed in single or double quotes are output as-is, and do not affect formatting.
    ; Separates sections for positive, negative, and zero numbers in the format string.
    The locations of the leftmost '0' before the decimal point in the format string and the rightmost '0' after the decimal point in the format string determine the range of digits that are always present in the output string.
    The number being formatted is always rounded to as many decimal places as there are digit placeholders ('0' or '#') to the right of the decimal point. If the format string contains no decimal point, the value being formatted is rounded to the nearest whole number.If the number being formatted has more digits to the left of the decimal separator than there are digit placeholders to the left of the '.' character in the format string, the extra digits are output before the first digit placeholder.
    To allow different formats for positive, negative, and zero values, the format string can contain between one and three sections separated by semicolons.One section: The format string applies to all values.
    Two sections: The first section applies to positive values and zeros, and the second section applies to negative values.
    Three sections: The first section applies to positive values, the second applies to negative values, and the third applies to zeros. If the section for negative values or the section for zero values is empty, that is if there is nothing between the semicolons that delimit the section, the section for positive values is used instead.If the section for positive values is empty, or if the entire format string is empty, the value is formatted using general floating-point formatting with 15 significant digits, corresponding to a call to FloatToStrF with the ffGeneral format. General floating-point formatting is also used if the value has more than 18 digits to the left of the decimal point and the format string does not specify scientific notation.
      

  4.   

    不好意思,能不能总结一下,用中文将最关键的部分介绍一下?
    详细介绍也不用详细到这种地步吧?呵呵
    你这从别的文档中copy过来的,让我不好给分啊,这不能反应你本人的水平,不过还是万分感谢你!
      

  5.   

    就是
    delphi的帮助你没看到吗