aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes formatting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "formatting" Watch "formatting" New topic
Author

formatting

shilpa Reddy
Ranch Hand

Joined: Jul 26, 2006
Posts: 42
.......i have doubt in formatting

int i1 = -123;
int i2 = 12345;

System.out.printf(">%0,7d< \n", i2);
System.out.format(">%+-7d< \n", i2);

result is

>012,345<
>+12345 <

can you explain me this......how did the comma go between 012 and y the - symbol was not inserted....

thanks...
Neelesh Bodas
Ranch Hand

Joined: Jul 20, 2006
Posts: 107
The - symbol was not printed since you are printing a positive integer (i2 is greater than zero)
and when the comma symbol is used to format the numbers, typically comma separates group of 3 digits from the RHS. Thus, 1234567 will be printed as 1,234,567
shilpa Reddy
Ranch Hand

Joined: Jul 26, 2006
Posts: 42
thanks for the reply...but i din get the concept of i2 greater than zero....
Rodolfo Velasco
Greenhorn

Joined: Jul 05, 2006
Posts: 17
When you use the - symbol , if you're printing a negative number .. it'll be printed inside parenthesys



result is

>(5355)<

Hope this helps...
shilpa Reddy
Ranch Hand

Joined: Jul 26, 2006
Posts: 42
that happens when you use "(" this symbol..... - will jus insert - i guess
Rodolfo Velasco
Greenhorn

Joined: Jul 05, 2006
Posts: 17
oo.. thanks..
is good to know..

 
jQuery in Action, 2nd edition
 
subject: formatting