Field specifiers for printf. : printf « String « Perl






Field specifiers for printf.

   
Specifier          Description 
%c                 Single character 
%d                 Integer in decimal (base-10) format 
%e                 Floating-point number in scientific notation 
%f                 Floating-point number in "normal" (fixed-point) notation 
%g                 Floating-point number in compact format 
%o                 Integer in octal (base-8) format 
%s                 Character string 
%u                 Unsigned integer 
%x                 Integer in hexadecimal (base-16) format 

   
    
    
  








Related examples in the same category

1.Format Codes for the sprintf and printf Functions
2.printf Data Formats
3.%.2f specifies a floating-point number with two decimal digits
4.%3d specifies that the integer number should be displayed with three digits
5.%x: Hexadecimal
6.Insert multiple values to printf
7.Output month name and week name by using the return value from gmtime
8.Printing a percent sign after a digit
9.Printing a space before signed values not preceded by + or -
10.Printing integers right-justified
11.Printing numbers with the + flag
12.Printing numbers without the + flag
13.Printing out an array of string one by one
14.Printing with the 0 (zero) flag fills in leading zeros
15.The printf formats a string and prints it to the given file handle:
16.To print a single text string using %s
17.Using precision while printing floating-point numbers
18.Using precision while printing integers
19.Using precision while printing strings
20.Using the # flag with conversion specifier X
21.Using the # flag with conversion specifier g
22.Using the # flag with conversion specifier o
23.printf "%+.4e\n", $value;
24.printf "%.5f\n", $value;
25.printf "%c is ASCII value 65 and %c is value 66\n", 65, 66;
26.printf "%d\n", +455.34;
27.printf "%d\n", -455;
28.printf "%d\n", 455.954;
29.printf "%o\n", 455;
30.printf "%u\n", -455;
31.printf "%u\n", 455;
32.printf "%x\n", -455;
33.printf "Left-justified the number is |%-10d|\n", 100;
34.printf "The character is %c\n", 65;
35.printf "The floating point number is |%8f|\n", 15;
36.printf "The formatted floating point number is |%8.2f|\n",14.3456;
37.printf "The formatted number is |%10d|\n", 100;
38.printf "The number in decimal is %d\n", 45;
39.printf "The number in hexadecimal is %x\n", 15;
40.printf "The number in octal is %o\n",15;
41.printf "The number printed with leading zeros is |%010d|\n", 5;
42.printf "This string is %s\n", "literal";
43.printf("%-15s%-20s\n", "Jack", "Sprat");