— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet282/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   278   279   280   281   282   283   284   285   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

%, d 
means “insert commas and format the 
number as a decimal integer.”
and
%.2f
means “format the number as a floating 
point with a precision of two decimal places.”
and
%,.2f 
means “insert commas and format the 
number as a floating point with a precision of 
two decimal places.”
The real question is really, “How do I know what 
to put after the percent sign to get it to do what 
I want?” And that includes knowing the symbols 
(like “d” for decimal and “f” for floating point) 
as well as the order in which the instructions 
must be placed following the percent sign. For 
example, if you put the comma after the “d” like 
this: “%d,” instead of “%,d” it won’t work!
Or will it? What do you think this will do:
But how does it even KNOW 
where the instructions end and the 
rest of the characters begin? How come 
it doesn’t print out the “f” in “%.2f”? Or 
the “2”? How does it know that the .2f 
was part of the instructions and NOT 
part of the String?
String.format(“I have %.2f, bugs to fix.”, 476578.09876);
(We’ll answer that on the next page.)


298
 
chapter 10
The format specifier
Everything after the percent sign up to and including the type indicator (like 
“d” or “f”) are part of the formatting instructions. After the type indicator, the 
formatter assumes the next set of characters are meant to be part of the output 
String, until or unless it hits another percent (%) sign. Hmmmm... is that even 
possible? Can you have more than one formatted argument variable? Put that 
thought on hold for right now; we’ll come back to it in a few minutes. For now, 
let’s look at the syntax for the format specifiers—the things that go after the 
percent (%) sign and describe how the argument should be formatted.
A format specifier can have up to five different parts (not 
including the “%”). Everything in brackets [ ] below is optional, so 
only the percent (%) and the type are required. But the order is 
also mandatory, so any parts you DO use must go in this order.

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   278   279   280   281   282   283   284   285   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish