Delphi formatted output function (1): Format

Source: Internet
Author: User
Tags value of pi

Var
s:string;
Begin
Directive type
S: = Format (' Max integer is:%d; the smallest integer is:%d ', [Maxint,low (integer)]);
Return: The largest integer is: 2147483647; The smallest integer is:-2147483648
{Hint: Format directives must start with%, case-insensitive,%d represents an integer; The second argument is a variant array}
S: = Format (' largest minus sign integer is:%u ', [High (cardinal)]);
Return: The largest unsigned integer is: 4294967295
{%u represents an integer without a minus sign}
S: = Format (' Input-2 result is:%u ', [-2]);
return: Input-2 results are: 4294967294
{if the corresponding%u is a negative number, return: No minus sign integer maximum-absolute value + 1}
S: = Format ('%s!%s ', [' Hello ', ' I am in case ']);
return: Hello! What if I
{%s represents a string}
S: = Format ('%f ', [Pi]);
Return: The value of pi is: 3.14
{%f represents floating point number, keep or scrape up two decimal points}
S: = Format ('%g ', [01.2345000]);
return: 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, and the integer part uses the thousand separator, leaving the two-bit decimal point}
S: = Format ('%m ', [12345.6789]);
return: ¥12,345.68
{%m represents a floating-point number with a currency token, the result of the conversion depends on the system's geographic setting}
S: = Format ('%e ', [12345.6789]);
return: 1.23456789000000E+004
{%e uses scientific notation to represent integers or floating-point numbers}
S: = Format ('%p ', [@Self]);
return: 0012F5BC
{%p represents the pointer address, in hexadecimal notation}
S: = Format ('%x ', [255]);
Back: 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: the first value in the corresponding array; 1: The second value in the corresponding array}
S: = Format ('%1:s%0:s ', [' million ', ' one ']);
Return: 10,000
{Flipped the Order}
S: = Format ('%1:s%0:s%0:s%1:s ', [' million ', ' one ']);
return: 100,000,001
{repeated use}
Width and alignment
S: = Format ('%d,%8d,%d ', [1,2,3]);
Return: 1, 2,3
{A 8-character width is specified for the second value, blank padding is missing, or invalid if specified less}
S: = Format ('%d,%-8d,%d ', [1,2,3]);
return: 1,2, 3
{-Is left aligned, the default is right-aligned;-symbol in front of Width, behind Index}
Specify Precision Prec
S: = Format ('%.9f ', [Pi]);
return: 3.141592654
{Specifies the number of digits for the decimal point, the value range 1-9, and the input 0 for 1.}
S: = Format ('%.5d ', [12]);
return: 00012
{This is a specified number of digits to an integer, which is invalid if it is small}
S: = Format ('%.3s ', [' format ']);
Back: For
{Specifies the number of digits to the string, invalid if large}
S: = Format ('%.3e ', [123.456]);
return: 1.23E+002
{Specify the number of digits for scientific notation}
Instruction Order:
{"%" [index]: "] ["-"] [width] [. prec] Type}
ShowMessage (s);
End

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.