
| Contents |
||||||||||||||||||||||||||||||||
| [an error occurred while processing this directive] |
2.2.1 Numeric LiteralsNumeric literals are simply constant numbers. Numeric literals are much easier to comprehend and use than string literals. There are only a few basic ways to express numeric literals. The numeric literal representations that Perl users are similar to those used in other languages such as C, Ada, and Pascal. The following are a few common examples:
42; # @cc{The number 42} 12.5; # @cc{A floating point number, twelve and a half} 101873.000; # @cc{101,873} .005 # @cc{five thousandths} 5E-3; # @cc{same number as previous line} 23e-100; # @cc{23 times 10 to the power of -100 (very small)} 2.3E-99; # @cc{The same number as the line above!} 23e6; # @cc{23,000,000} 23_000_000; # @cc{The same number as line above} # @cc{The underscores are for readability only}
As you can see, there are three basic ways to express numeric literals.
The most simple way is to write an integer value, without a decimal
point, such as
You can also write numeric literals with a decimal point. So, you can
write numbers like
Probably the most complex method of expressing a numeric literal is
using what is called exponential notation. These are numbers of
the form
b * 10^x
, where b is some decimal number, positive or negative, and
x is some integer, positive or negative. Thus, you can express
very large numbers, or very small numbers that are mostly 0s
(either to the right or left of the decimal point) using this notation.
However, when you write such a number as a literal in Perl, you must
write it in the from
Finally, if you write out a very large number, such as
|