86
❘
CHAPTER 5
InteractIng wIth StructureS and ObjectS
oPTIoN
MEANINg
‘x’
Outputs the number as a base 16 (hexadecimal) value. The interpreter uses
lowercase characters for any value above 9 and also for the base indicator.
‘X’
Outputs the number as a base 16 (hexadecimal) value. The interpreter uses
uppercase characters for any value above 9 and also for the base indicator.
‘n’
Outputs the number as a base 10 (decimal) value. However,
this setting uses
the user’s locale setting for separator characters. For example, many coun-
tries use the comma for the decimal point instead of a period.
TAblE 5-4:
Floating Point and Decimal Formatting Types
oPTIoN
MEANINg
‘e’
Outputs the number in exponent (scientific notation) form,
using the letter
‘e’ (lowercase) to indicate the exponent.
‘E’
Outputs the number in exponent (scientific notation) form, using the letter
‘E’ (uppercase) to indicate the exponent.
‘f’ or ‘F’
Outputs the number in fixed-point format.
‘g’
Outputs the number in a general format. The presentation depends on the
numeric magnitude. Smaller numbers
appear in fixed-point format, while larger
numbers appear in scientific notation.
The rules for determining whether a number appears in either fixed-point or
scientific notation
are relatively complex, but are based on the size and preci-
sion of the number. If a number would require too many zeros (due to being
too large or too small)
to present as fixed point, the interpreter automatically
chooses scientific notation. No matter how the interpreter presents the num-
ber, it removes insignificant trailing zeros.
In addition, the interpreter removes
the decimal point if there aren’t any digits following it.
The interpreter also presents positive infinity as inf,
negative infinity as -inf,
positive zero as 0, negative zero as -0, and Not-a-Number (NaN) as nan. You
can read more about these special value representations at
http://steve
.hollasch.net/cgindex/coding/ieeefloat.html
.
‘G’
Outputs the number in general format using the same requirements as the ‘g’
type. The difference is that this type uses an uppercase ‘E’ for scientific nota-
tion. Both representations of infinity and NaN appear in uppercase as well.
‘n’
Outputs the number in general format using the
same requirements as the
‘g’ type. This type differs because it relies on the user’s current locale set-
tings to insert the appropriate number separator characters.
‘%‘
Outputs the number as a percentage by multiplying the number by 100 and
appending a percent sign.
TAblE 5-3
(continued)
548592c05.indd 86
2/24/10 1:21:48 PM
www.finebook.ir