Package java.text

Examples of java.text.NumberFormat


      unit = "kB";
    } else {
      return bytes + " Byte";
    }

    NumberFormat format = NumberFormat.getInstance(locale);
    format.setMinimumFractionDigits(fractionDigits);
    format.setMaximumFractionDigits(fractionDigits);

    String asString = format.format((double) bytes / (double) factor);

    return asString + " " + unit;
  }
View Full Code Here


              + ((secs > 9) ? "" : "0") + secs + " h";
    } else if (mins != 0) {
      return mins + ":"
              + ((secs > 9) ? "" : "0") + secs + " min";
    } else if (secs != 0) {
      NumberFormat format = NumberFormat.getInstance();
      format.setMinimumFractionDigits(2);
      format.setMaximumFractionDigits(2);

      String asString = format.format(secs + millis / 1000.0);

      return asString + " sec";
    } else {
      return millis + " millis";
    }
View Full Code Here

      }

      int cache_index = (precision << 2) + ((bTruncateZeros ? 1 : 0) << 1)
          + (bRound ? 1 : 0);

      NumberFormat nf = null;

      if (cache_index < cached_number_formats.length) {
        nf = cached_number_formats[cache_index];
      }

      if (nf == null) {
        nf = NumberFormat.getNumberInstance();
        nf.setGroupingUsed(false); // no commas
        if (!bTruncateZeros) {
          nf.setMinimumFractionDigits(precision);
        }
        if (bRound) {
          nf.setMaximumFractionDigits(precision);
        }

        if (cache_index < cached_number_formats.length) {
          cached_number_formats[cache_index] = nf;
        }
      }

      return nf.format(tValue);
    }
View Full Code Here

      oCurr = Currency.getInstance(oLoc);
    }
    else if (!sCurrency.equals(sCurr)) {
      oCurr = Currency.getInstance(sCurrency);
    }
    NumberFormat oFmtC = NumberFormat.getCurrencyInstance(oLoc);
    oFmtC.setCurrency(oCurr);
    return oFmtC.format(oDec.doubleValue());
  }
View Full Code Here

      oCurr = Currency.getInstance(oLoc);
    }
    else if (!sCurrency.equals(sCurr)) {
      oCurr = Currency.getInstance(sCurrency);
    }
    NumberFormat oFmtC = NumberFormat.getCurrencyInstance(oLoc);
    oFmtC.setCurrency(oCurr);
    return oFmtC.format(oDec.doubleValue());
  }
View Full Code Here

   * @param oLocale Locale used for formatting
   * @return String
   * @see <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Locale.html">java.util.Locale</a>
   */
  public static String formatCurrency (BigDecimal oDec, String sCurrency, Locale oLocale) {
    NumberFormat oFmtC;
    if (null==oDec) return null;

    if (null==sCurrency) {
      oCurr = Currency.getInstance(oLocale==null ? Locale.getDefault() : oLocale);
    }
    else if (!sCurrency.equals(sCurr)) {
      oCurr = Currency.getInstance(sCurrency);
    }
    if (null==oLocale)
      oFmtC = NumberFormat.getCurrencyInstance(Locale.getDefault());
    else
      oFmtC = NumberFormat.getCurrencyInstance(oLocale);
    oFmtC.setCurrency(oCurr);
    return oFmtC.format(oDec.doubleValue());
  } // formatCurrency
View Full Code Here

      oLoc = new Locale(sLanguage,sCountry);
    else if (null!=sLanguage)
      oLoc = new Locale(sLanguage);
    else
      oLoc = Locale.getDefault();
    NumberFormat oFmtC = NumberFormat.getCurrencyInstance(oLoc);
    oFmtC.setCurrency(currencyCode().currency());
    return oFmtC.format(doubleValue());
  } // format
View Full Code Here

    // Systemspeziefischen Zeilenumbruch holen
    String lineSeparator = RegainToolkit.getLineSeparator();

    // Statistik ausgeben
    StringBuffer buffer = new StringBuffer(mName + ":");
    NumberFormat integerFormat = NumberFormat.getInstance();
    integerFormat.setMaximumFractionDigits(0);
    if (abortedMeasureCount > 0) {
      buffer.append(lineSeparator);

      appendLabel(buffer, "Aborted " + mUnit, minLabelLength);
      buffer.append(integerFormat.format(abortedMeasureCount) + " " + mUnit + " (");

      // Ausgeben, wieviel % der Messungen fehl schlugen
      int total = abortedMeasureCount + measureCount;
      double errorPercent = (double) abortedMeasureCount / (double) total;
      buffer.append(RegainToolkit.toPercentString(errorPercent));

      buffer.append(")");
    }
    if (measureCount > 0) {
      buffer.append(lineSeparator);

      appendLabel(buffer, "Completed " + mUnit, minLabelLength);
      buffer.append(integerFormat.format(measureCount) + " " + mUnit + lineSeparator);

      appendLabel(buffer, "Total time", minLabelLength);
      buffer.append(RegainToolkit.toTimeString(totalTime) + lineSeparator);

      appendLabel(buffer, "Total data", minLabelLength);
      buffer.append(RegainToolkit.bytesToString(totalBytes) + lineSeparator);

      appendLabel(buffer, "Average time", minLabelLength);
      buffer.append(RegainToolkit.toTimeString(averageTime) + lineSeparator);

      appendLabel(buffer, "Average data", minLabelLength);
      buffer.append(RegainToolkit.bytesToString(averageBytes) + lineSeparator);

      appendLabel(buffer, "Data rate", minLabelLength);
      buffer.append(RegainToolkit.bytesToString(dataRatePerSec) + "/sec" + lineSeparator);

      appendLabel(buffer, "Output", minLabelLength);
      if (countsPerMinute > 10) {
        // No decimals when the count is high
        buffer.append(integerFormat.format(countsPerMinute) + " " + mUnit + "/min");
      } else {
        NumberFormat floatingFormat = NumberFormat.getInstance();
        floatingFormat.setMinimumFractionDigits(2);
        floatingFormat.setMaximumFractionDigits(2);
        buffer.append(floatingFormat.format(countsPerMinute) + " " + mUnit + "/min");
      }
    }

    return buffer.toString();
  }
View Full Code Here

      list.toArray(mExtensionArr);

      if (mLog.isDebugEnabled()) {
        double duration = (double) (System.currentTimeMillis() - startTime) / 1000.0;

        NumberFormat format = NumberFormat.getInstance();
        format.setMinimumFractionDigits(2);
        format.setMaximumFractionDigits(2);

        mLog.debug("Getting the supported extensions of the IfilterPreparator took "
            + format.format(duration) + " secs");
      }
    }

    return mExtensionArr;
  }
View Full Code Here

    Document doc=new Document();
    Enumeration nameIter=prop.propertyNames();
    while(nameIter.hasMoreElements()){
      String name=(String)nameIter.nextElement();
      NumberFormat format=formatterHash.get(name);
      String val=prop.getProperty(name);
     
      String[] vals=val.split(",");
      for (int i=0;i<vals.length;++i){
        if (vals[i]!=null && vals[i].length()>0){
          if (format!=null){
            vals[i]=format.format(Double.parseDouble(vals[i]));
          }
          doc.add(new Field(name,vals[i],Field.Store.NO,Field.Index.NOT_ANALYZED,Field.TermVector.NO));
        }
      } 
    }
View Full Code Here

TOP

Related Classes of java.text.NumberFormat

Copyright © 2018 www.massapicom. 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.