⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doubleformat.java

📁 一个java工作流引擎
💻 JAVA
字号:
package org.jbpm.web.formgen.format;

import java.text.DecimalFormat;
import java.text.FieldPosition;
import java.text.Format;
import java.text.ParseException;
import java.text.ParsePosition;


public class DoubleFormat extends Format {
  
  DecimalFormat decimalFormat = new DecimalFormat();
  
  public DoubleFormat() {
    decimalFormat = new DecimalFormat("0.####################################");
  }

  public Object parseObject(String source, ParsePosition pos) {
    Double result = null;
    
    if ( source != null ) {
      try { 
        result = new Double(decimalFormat.parse(source).doubleValue());
        pos.setErrorIndex(-1);
        pos.setIndex(source.length());
      }
      catch(ParseException e) {
        pos.setErrorIndex(e.getErrorOffset());
      }
    }

    return result;
  }

  public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
    if ( obj != null ) {
      toAppendTo.append(decimalFormat.format(obj));
    }
    return toAppendTo;
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -