Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 String.format
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Panphobia




PostPosted: Tue Jan 01, 2013 1:43 am   Post subject: String.format

I am not exactly sure how to use it at all actually, I could not find it on the API, i went under formatter also but nothing, I just saw it in a program, and I wanted to see if it does what I thought it did, I thought it could cut out X characters from a string, but i am not sure, if you guys know the correct API could you link me? and also if you can't find one can you explain how to use it and what it does?
Sponsor
Sponsor
Sponsor
sponsor
Panphobia




PostPosted: Tue Jan 01, 2013 1:51 am   Post subject: Re: String.format

I mean something like this, what would it do to a random string
code:
System.out.println(String.format("%.10f", lol));
Insectoid




PostPosted: Tue Jan 01, 2013 10:38 am   Post subject: RE:String.format

String.format works like printf in C. You type in a string with some modifiers in it followed by a list of variables. String.format will replace the modifiers with the variables and format them accordingly. Your example is an incorrect usage of the function. %f represents a float, and the .10 is the number of decimal points to output. If you did something like
code:
String.format("%.10f", 1/3)
, it would output 0.3333333333. There is a list of modifiers here.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: