Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Perl >> Snippet

print samples


printf ( "%20s" , "Jack" );       # right-justify "Jack" in a 20 characters

printf ( "%-20s" , "Jack" );      # left-justify "Jack" in a 20 characters

$amt = 7.12;
printf ( "%6.2f" , $amt );        # prints "    7.12"

$amt = 7.127;
printf ( "%6.2f" , $amt );        # prints "    7.13" extra digit rounded

printf ( "%c" , 65);            # print ASCII character for 65, "A"

$amt = 9.4
printf ( "%6.2f" , $amt );        # prints "    9.40"

$amt = 9.4
printf ( "%6d" , $amt );          # prints "     9"

$amt = 9.4
printf ( "%06d" , $amt );          # prints "000009"   0 in front of the 6 says to show leading zeros