Printing numbers with the + flag : printf « String « Perl






Printing numbers with the + flag

  

#!usr/bin/perl

use warnings;
use strict;

printf "%+d\n%+d\n", 786, -786;

   
    
  








Related examples in the same category

1.Field specifiers for printf.
2.Format Codes for the sprintf and printf Functions
3.printf Data Formats
4.%.2f specifies a floating-point number with two decimal digits
5.%3d specifies that the integer number should be displayed with three digits
6.%x: Hexadecimal
7.Insert multiple values to printf
8.Output month name and week name by using the return value from gmtime
9.Printing a percent sign after a digit
10.Printing a space before signed values not preceded by + or -
11.Printing integers right-justified
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");