Package java.text

Examples of java.text.DecimalFormat.applyPattern()


  public static String formatNumberCN(String number, String formatStr) {
    if(number==null || number.length()<1){
      return "";
    }
    DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.CHINA);
    df.applyPattern(formatStr);
    String numberStr = df.format(Double.parseDouble(number));
    return numberStr;
  }

  /**
 
View Full Code Here


   * @param number 被格式化的数字
   * @return 返回格式化后的数字的对应的字符串
   */
  public static String formatNumberCN(double number) {
    DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.CHINA);
    df.applyPattern(NUMBER_IN_2_0);
    return df.format(number);
  }

  /**
   * 将给定的一个数字字符串按中国的习惯和按始终显示两位小数,整数部分超过3位时不用","分开的格式格式化
 
View Full Code Here

  public static String formatNumberCN(String number) {
    if(number==null || number.length()<1){
      return "";
    }
    DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.CHINA);
    df.applyPattern(NUMBER_IN_2_0);
    return df.format(Double.parseDouble(number));
  }

  /**
   *将给定的一个数字按指定的国家的风格和指定的格式来格式化它,并返回一个该数字对应的字符串
 
View Full Code Here

    protected String FormatNumber(double d) {
      DecimalFormat nf = new DecimalFormat();
      String ret;
      // If module of number is greater than 1e4 or lesser than 1e-4 uses exponential notation
      if (Math.abs(d) >= 1e-4 && Math.abs(d) <= 1e4 || d == 0) {
        nf.applyPattern("#.####");
        ret = nf.format(d);
        if (ret.length() > 7) {
          ret = ret.substring(0, 6);
        }
      } else {
View Full Code Here

        ret = nf.format(d);
        if (ret.length() > 7) {
          ret = ret.substring(0, 6);
        }
      } else {
        nf.applyPattern("0.00E00");
        ret = nf.format(d);
      }
      return ret;
    }
View Full Code Here

            ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();

    format = NumberFormat.getIntegerInstance();
    if (format instanceof DecimalFormat) {
      DecimalFormat decf = (DecimalFormat)format;
      decf.applyPattern(decf.toPattern()+" KB");
    }
    stats.add(new StatRecord(getName(), "Max Heap mem", "long",
            format.format(heap.getMax()/1024), Level.INFO));
    stats.add(new StatRecord(getName(), "Used Heap", "long",
            format.format(heap.getUsed()/1024), Level.INFO));
View Full Code Here

  public void check1Min(Queue<Packet> results) {
    for (File file : roots) {
      NumberFormat format = NumberFormat.getIntegerInstance();
      if (format instanceof DecimalFormat) {
        DecimalFormat decf = (DecimalFormat) format;
        decf.applyPattern(decf.toPattern() + " KB");
      }
      NumberFormat formp = NumberFormat.getPercentInstance();
      formp.setMaximumFractionDigits(2);
      double percent = new Long(file.getUsableSpace()).doubleValue() /
              new Long(file.getTotalSpace()).doubleValue();
View Full Code Here

    if (note.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
      log.info("Usage threshold exceeded, sending notification.");
      NumberFormat format = NumberFormat.getIntegerInstance();
      if (format instanceof DecimalFormat) {
        DecimalFormat decf = (DecimalFormat) format;
        decf.applyPattern(decf.toPattern() + " KB");
      }
      MemoryPoolMXBean memoryPoolMXBean = (MemoryPoolMXBean) handback;
      String message = "Threshold " +
              format.format(memoryPoolMXBean.getUsageThreshold() / 1024) +
              " for memory pool: " + memoryPoolMXBean.getName() +
View Full Code Here

  public String getState() {
    NumberFormat format = NumberFormat.getIntegerInstance();
    if (format instanceof DecimalFormat) {
      DecimalFormat decf = (DecimalFormat) format;
      decf.applyPattern(decf.toPattern() + " KB");
    }
    NumberFormat formp = NumberFormat.getPercentInstance();
    formp.setMaximumFractionDigits(2);
    StringBuilder sb = new StringBuilder();
    List<MemoryPoolMXBean> memPools = ManagementFactory.getMemoryPoolMXBeans();
View Full Code Here

        if (patternKey != null) {
            String pattern =
                ResourceService.getService().getLocalizedFormat(StringTable,
                    patternKey,
                    locale);
            fmt.applyPattern(pattern);
        }

        formatCache.put(locale, fmt);

        return fmt;
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.