Delphi formatted output function (1): Format

Source: Internet
Author: User
Tags value of pi

Var
s:string;
Begin
Instruction type
S: = Format (' Maximum integer is:%d; minimum integer is:%d ', [Maxint,low (integer)]);
Return: The maximum integer is: 2147483647; Minimum integer is:-2147483648
{hint: The format instruction must start with%, is case-insensitive,%d represents an integer, and the second argument is a variant array}
S: = Format (' Maximum no minus sign integer is:%u ', [High (Cardinal)]);
Returns: The largest no minus sign integer is: 4294967295
{%u denotes a non-negative integer}
S: = Format (' Input-2 results are:%u ', [-2]);
Returns: Input-2 of the result is: 4294967294
{if the corresponding%u is a negative number, returns: No minus sign integer maximum-the absolute value of this digit + 1}
S: = Format ('%s!%s ', [' Hello ', ' I was in case ')];
Back to: Hello! I was in case
{%s represents a string}
S: = Format ('%f ', [Pi]);
Return: The value of pi is: 3.14
{%f represents a floating-point number, keeping or rounding two decimal places}
S: = Format ('%g ', [01.2345000]);
Returns: 1.2345
{%g represents a floating-point number, removing the extra 0}
S: = Format ('%n ', [12345.6789]);
return: 12,345.68
{%n represents a floating-point number, the integer part uses the thousand separator, and two decimal places are reserved}
S: = Format ('%m ', [12345.6789]);
return: ¥12,345.68
{%m represents a floating-point number, plus a currency tick, and the result depends on the locale of the system}
S: = Format ('%e ', [12345.6789]);
Returns: 1.23456789000000E+004
{%e represents an integer or floating-point number by scientific notation}
S: = Format ('%p ', [@Self]);
return: 0012F5BC
{%p represents a pointer address, in hexadecimal notation}
S: = Format ('%x ', [255]);
Back to: FF
{%x denotes an integer in hexadecimal}
Index
S: = Format ('%s%s ', [' million ', ' one ']);
S: = Format ('%0:s%1:s ', [' million ', ' one ']);
Back: In case
{The result of the above two lines is the same, 0: corresponds to the first value in the array; 1: Corresponds to the second value in the array}
S: = Format ('%1:s%0:s ', [' million ', ' one ']);
Returns: 10,000
{Flip the Order}
S: = Format ('%1:s%0:s%0:s%1:s ', [' million ', ' one ']);
Returns: 100,000,001
{repeated use}
Width and alignment
S: = Format ('%d,%8d,%d ', [n/a]);
Returns: 1, 2,3
{A 8-character width is specified for the second value, a missing space is filled in, or invalid if the specified is less}
S: = Format ('%d,%-8d,%d ', [n/a]);
Back to: 3
{-Indicates left-justified, right-aligned by default;-Symbol at Width front, Index after}
Specifying precision PREC
S: = Format ('%.9f ', [Pi]);
Returns: 3.141592654
{Specify the number of digits in the decimal point, value range 1-9, input 0 also when 1 is used}
S: = Format ('%.5d ', [12]);
Returns: 00012
{This is a specified number of digits for an integer and is invalid if it is small}
S: = Format ('%.3s ', [' format ']);
return: For
{Specifies the number of bits for a string and is invalid if it is large}
S: = Format ('%.3e ', [123.456]);
Returns: 1.23E+002
{Specify number of digits for scientific notation}
Order of instruction:
{"%" [index]: "] ["-"] [width] [". "Prec] Type}
ShowMessage (s);
End

Delphi formatted output function (1): Format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.