Demos and Usage of java.lang.String.format(String format,... args)


   1: {  
   2:    public static void main(String[] args)
   3:    {  
   4:         ...
   5:       double futureBalance = INITIAL_BALANCE * Math.pow(1 + rate, nperiods);
   6:       return String.format("%.2f", futureBalance);
   7:    }
   8:         ...
   9: 
  10:    public String getColumnName(int c) { return (c + minRate) + "%"; }

View Full Code Here
   1:         
   2:             if(v instanceof String)
   3:             {
   4:         ...
   5:                 String str = (String) v;
   6:                 str = str.replace(',', '.');
   7:                 
   8:                 try

View Full Code Here
   1:     public static class MemStorage extends AbstractGripStorage {
   2:         public TreeSet<String> nurseNames = new TreeSet<String>();
   3: 
   4:         ...
   5:         @Override
   6:         public String[] getNurseNames() {
   7:             return nurseNames.toArray(new String[0]);
   8:         ...
   9:                                     .format(
  10:                                             "String.format(\"%.3f\", 4.512) = \"%s\" instead of \"4.512\". Check internationalization settings.",
  11:         ...
  12:                                             String.format("%.3f", 4.512)));

View Full Code Here
   1:     @Override
   2:     public String toString() {
   3:         return display();
   4:         ...
   5: 
   6:     public String display() {
   7:         ...
   8:         String ret = "<";
   9:         boolean first = true;
  10:         ...
  11:             double d = queue.getPriority(n);
  12:             ret += "(" + n.component + "/" + String.format("%.4f", d) + "/"

View Full Code Here
   1: 
   2:     public static void main(String[] args) throws Exception {
   3:         Random r = new Random();
   4:         ...
   5:         String uniqString = "";
   6:         for (int i = 0; i < 4; i++) {
   7:         ...
   8:         }
   9:         final String uString = uniqString;
  10:         int b;
  11:         ...
  12:     public void checkConfiguration() {
  13:         if (!String.format("%.3f", 4.512).equals("4.512")) {

View Full Code Here
   1: 
   2:                     public String convertObjectToString(Object object) {
   3:                         if (object == root) {
   4:         ...
   5:     private class NameValueList {
   6:         private String[] names;
   7: 
   8:         ...
   9:         private String[] values;
  10: 
  11:         ...
  12:         }
  13:         l.values = new String[] { String.format("%.4f", stateRegion.value),

View Full Code Here
   1: 
   2:   private static final String output_SWITCH = "output";
   3:         ...
   4:   private static final String dir_SWITCH = "dir";
   5:         ...
   6:   private static final String conf_SWITCH = "conf";
   7:   private static final String filter_SWITCH = "filter";
   8:         ...
   9:     double s = portion * 100;
  10:     return String.format("%.2f",s /total)+"%";

View Full Code Here