Examples of DecimalFormat


Examples of com.ibm.icu.text.DecimalFormat

        // problem 2
        double number = 8.88885;
        String expected = "8.8889";
       
        String pat = ",##0.0000";
        DecimalFormat dec = new DecimalFormat(pat);
        dec.setRoundingMode(BigDecimal.ROUND_HALF_UP);
        double roundinginc = 0.0001;
        dec.setRoundingIncrement(roundinginc);
        String str = dec.format(number);
        if (!str.equals(expected)) {
            errln("Fail: " + number + " x \"" + pat + "\" = \"" +
                  str + "\", expected \"" + expected + "\"");
        }  

        pat = ",##0.0001";
        dec = new DecimalFormat(pat);
        dec.setRoundingMode(BigDecimal.ROUND_HALF_UP);
        str = dec.format(number);
        if (!str.equals(expected)) {
            errln("Fail: " + number + " x \"" + pat + "\" = \"" +
                  str + "\", expected \"" + expected + "\"");
       
       
        // testing 20 decimal places
        pat = ",##0.00000000000000000001";
        dec = new DecimalFormat(pat);
        BigDecimal bignumber = new BigDecimal("8.888888888888888888885");
        expected = "8.88888888888888888889";
       
        dec.setRoundingMode(BigDecimal.ROUND_HALF_UP);
        str = dec.format(bignumber);
        if (!str.equals(expected)) {
            errln("Fail: " + bignumber + " x \"" + pat + "\" = \"" +
                  str + "\", expected \"" + expected + "\"");
        }  
       
View Full Code Here

Examples of java.text.DecimalFormat

      progressStr.append(httpToolDocSize / 1024);
      progressStr.append(" kB");
    }

    // ratio
    DecimalFormat myFormat = new DecimalFormat("####0.000");
    progressStr.append(", ");
    progressStr.append(myFormat.format((float)(ratio)/1000));
    progressStr.append(" kB/s");

   
    // time left
    if (this.httpToolDocSize > 0) {
View Full Code Here

Examples of java.text.DecimalFormat

  /**
   * update status of dynamic elements
   */
  protected void updateControls() {
    DecimalFormat myFormat = new DecimalFormat("###,###,###.0");
    String retrievedContent=
      robotCount+" files with "
      +myFormat.format((float)robotSize/1024)
      +" kB";
    String queuedContent=robotQueueSize+"";
    retrievedField.setText(retrievedContent);
    queuedField.setText(queuedContent);
  }
View Full Code Here

Examples of java.text.DecimalFormat

              NumberFormat currencyFormat;
              if (currency != null) {
                currencyFormat = DecimalFormat.getCurrencyInstance();
                currencyFormat.setCurrency(Currency.getInstance(currency));
              } else {
                currencyFormat = new DecimalFormat("##0.00");
              }
              value = currencyFormat.format(value);
            } else {
              value = "";
            }
View Full Code Here

Examples of java.text.DecimalFormat

    Set listkey = itemLines.keySet();
    Iterator it = listkey.iterator();
    String itemExternalID = "";
    int id = 0;
    String fmt = "0.00#";
    DecimalFormat df = new DecimalFormat(fmt, new DecimalFormatSymbols(Locale.US));

    Integer itemID = new Integer(1);

    while (it.hasNext())
    {

      Object obj = it.next();

      itemID = Integer.valueOf(obj.toString());

      ItemElement ele = (ItemElement)itemLines.get(itemID.toString());

      IntMember ItemId = (IntMember)ele.get("ItemId");

      id = Integer.valueOf(ItemId.getDisplayString()).intValue();
      //itemID = (Integer)ItemId.getMemberValue();
      itemExternalID = getEXIDFromID("Item", id);

      StringMember sku = (StringMember)ele.get("SKU");

      FloatMember qty = (FloatMember)ele.get("Quantity");

      FloatMember priceEach = (FloatMember)ele.get("PriceEach");

      FloatMember priceExe = (FloatMember)ele.get("PriceExtended");

      qbTags += "<" + tagName + "> \n" + "<ItemRef> \n" + "<ListID>" + itemExternalID + "</ListID> \n" + "</ItemRef> \n" + "<Quantity>" + df.format(Float.valueOf(qty.getMemberValue().toString())) + "</Quantity> \n" + "<Rate>" + df.format(Float.valueOf(priceEach.getMemberValue().toString())) + "</Rate> \n" + "<Amount>"
          + df.format(Float.valueOf(priceExe.getMemberValue().toString())) + "</Amount> \n" + "</" + tagName + "> \n";
    }
    return qbTags;
  }
View Full Code Here

Examples of java.text.DecimalFormat

  public String getDisplayString()
  {
    if(auth == ModuleFieldRightMatrix.NONE_RIGHT)
      return "";
   
    DecimalFormat currencyFormat = new DecimalFormat("###,###,##0.00");
    String returnString = currencyFormat.format(memberValue);
    return returnString;
  } //end of getDisplayString method
View Full Code Here

Examples of java.text.DecimalFormat

        if(offset >= 0) {
          description.append("+");
        }
        description.append(hour);
        description.append(":");
        DecimalFormat df = new DecimalFormat("00");
        description.append(df.format(min));
        description.append(")");
        if (!descriptionList.contains(description)) {
          timeZoneColl.add(new DDNameValue(zoneIds[i], description.toString()));
          descriptionList.add(description);
        }
View Full Code Here

Examples of java.text.DecimalFormat

      }
      case FieldDecoration.fileSizeType:
        // display the string to file Size
        // which in byte to GB,MB,KB
        float size = (new Float(content.toString())).floatValue();
        DecimalFormat df = new DecimalFormat("###.#");
        Integer s = new Integer((int) size);
        valueString = s.toString();
        if (size > 1000000000) {
          size /= 1073741824; // 1GB
          valueString = df.format(size) + "GB";
        } else if (size > 1000000) {
          size /= 1048576; // 1MB
          valueString = df.format(size) + "MB";
        } else if (size > 1000) {
          size /= 1024; // 1KB
          valueString = df.format(size) + "KB";
        }
        decoratedField.append(valueString);
        break;

      case FieldDecoration.moneyType:
View Full Code Here

Examples of java.text.DecimalFormat

        swarm_completion = DisplayFormatters.formatPercentFromThousands( comp );
      }
     
      piecesDoneAndSum = pm.getPiecePicker().getNbPiecesDone() + "/" + piecesDoneAndSum;
     
      distributedCopies = new DecimalFormat("0.000").format(pm.getPiecePicker().getMinAvailability()-pm.getNbSeeds()-(pm.isSeeding()&&stats.getDownloadCompleted(false)==1000?1:0));
    }
   
   

    setStats(
View Full Code Here

Examples of java.text.DecimalFormat

        }
        return buf.toString();
    }

    public static String formatNumber(final long number) {
        DecimalFormat f = new DecimalFormat("#,###");
        return f.format(number);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.