string formatting - What does the numbers in Java printf() mean? -


when see in java, know .2 decimal place, f float, n newline, etc. 6?

system.out.printf("%6.2f2%n", somedouble); 

it stands length of string returned printf method. in case string @ least 6 characters long.

which means if

somedouble=pi 

then

system.out.printf("%6.2f2%n", somedouble); 

will print out string

"  3.14" 

(i.e. 2 whitespaces followed 4 characters containing 3.14)

another example

system.out.printf("%2.2f2%n", somedouble); 

which prints out

"3.14" 

we can see this not override .2 or else in command if shorter value given needed other rules apply.

so makes sure there whitespace preceding value.


Comments

Popular posts from this blog

python - Mongodb How to add addtional information when aggregating? -

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

ruby - Net::HTTP extremely slow responses for HTTPS requests -