printf Data Formats : printf « String « Perl

Home
Perl
1.Array
2.CGI
3.Class
4.Data Type
5.Database
6.File
7.GUI
8.Hash
9.Language Basics
10.Network
11.Regular Expression
12.Report
13.Statement
14.String
15.Subroutine
16.System Functions
17.Win32
18.XML
Perl » String » printf 




printf Data Formats
   


#!/usr/local/bin/perl

printf "% 16.2c 16.2c   - character format\n"0xF7;

printf "% 16.2d 16.2d   - decimal format\n"12382.12333;

printf "% 16.2e 16.2e   - exponential format\n"82123.12333;

printf "% 16.2f 16.2f   - floating point format\n", -81232.12333;

printf "% 16.2g 16.2g   - compact format\n"12382.12333;

printf "% 16.2ld 16.2ld  - long decimal format\n", -12382.12333;

printf "% 16.2lo 16.2lo  - long octal format\n"0xF7;

printf "% 16.2lu 16.2lu  - long unsigned format\n", -12382.12333;

printf "% 16.2lx 16.2lx  - long hex format\n"0xF7;

printf "% 16.2o 16.2o   - octal format\n"0xF7;

printf "% 16.2s 16.2s   - string format\n"0xF7;

printf "% 16.2u 16.2u   - unsigned format\n", -12382.12333;

printf "% 16.2x 16.2x   - hex format\n"0xF78;

printf "% 16.2X 16.2X   - upper case hex format\n"0xF7;

   
    
    
  














Related examples in the same category
1.Field specifiers for printf.
2.Format Codes for the sprintf and printf Functions
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");
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.