Example usage for java.text DecimalFormat format

List of usage examples for java.text DecimalFormat format

Introduction

In this page you can find the example usage for java.text DecimalFormat format.

Prototype

public final String format(double number) 

Source Link

Document

Specialization of format.

Usage

From source file:org.sunzoft.sunstock.StockMain.java

protected String getStatusText() {
    AccountStatus startStatus = profits.get(0);
    AccountStatus endStatus = profits.get(profits.size() - 1);
    float win = endStatus.market - endStatus.capital - startStatus.market + startStatus.capital;
    DecimalFormat formater = new DecimalFormat("0.00");
    return "?" + startStatus.capital + ""
            + formater.format(startStatus.market - startStatus.capital) + "?"
            + endStatus.capital + ""
            + formater.format(endStatus.market - endStatus.capital) + ""
            + formater.format(win) + "" + formater.format(win * 100 / endStatus.capital) + "%";
}

From source file:com.shmsoft.dmass.main.SHMcloudMain.java

private void processEnronDataSet() {
    int ENRON_SET_SIZE = 154;
    String localDir = "freeeed-output/";
    String output = "output/";
    String dir = "/mnt/tmp/";
    new File(dir + "results").mkdirs();
    for (int i = 1; i <= ENRON_SET_SIZE; ++i) {
        try {//w  w w  .ja  v  a 2s.co  m
            DecimalFormat decimalFormat = new DecimalFormat("enron000");
            String projectName = decimalFormat.format(i);
            if (new File(dir + projectName + ".project").exists() == false) {
                continue;
            }
            String outputPath = dir + "results/" + projectName + "/";
            if (new File(outputPath).exists()) {
                continue;
            }
            File localDirFile = new File(localDir);
            if (localDirFile.exists()) {
                Util.deleteDirectory(localDirFile);
            }
            String[] argv = new String[2];
            argv[0] = "-param_file";
            argv[1] = dir + projectName + ".project";
            processOptions(argv);
            // copy to local output dir
            new File(outputPath).mkdirs();
            String command = "cp " + localDir + output + "native.zip " + outputPath + projectName + ".zip";
            PlatformUtil.runUnixCommand(command);
            command = "cp " + localDir + output + "part-r-00000 " + outputPath + projectName
                    + ParameterProcessing.METADATA_FILE_EXT;
            PlatformUtil.runUnixCommand(command);
            command = "mv logs/stats.txt " + outputPath + projectName + ".txt";
            PlatformUtil.runUnixCommand(command);
            // place on amazon s3
            // like this, aws put freeeed.org/enron/results/enron001/enron001.zip enron001.zip
            command = "aws put freeeed.org/enron/results/" + projectName + ".zip " + outputPath + projectName
                    + ".zip";
            PlatformUtil.runUnixCommand(command);
            command = "aws put freeeed.org/enron/results/" + projectName + ".csv " + outputPath + projectName
                    + ParameterProcessing.METADATA_FILE_EXT;
            PlatformUtil.runUnixCommand(command);
            command = "aws put freeeed.org/enron/results/" + projectName + ".txt " + outputPath + projectName
                    + ".report.txt";
            PlatformUtil.runUnixCommand(command);
        } catch (Exception e) {
            e.printStackTrace(System.out);
        }
    }
}

From source file:edu.isi.karma.research.modeling.ModelLearner_KnownModels.java

private static double roundDecimals(double d, int k) {
    String format = "";
    for (int i = 0; i < k; i++)
        format += "#";
    DecimalFormat DForm = new DecimalFormat("#." + format);
    return Double.valueOf(DForm.format(d));
}

From source file:mx.redhat.jbpm.CustomType.FileCustomType.java

protected String getFileSize(long longSize) {
    double size = longSize;
    int position;
    for (position = 0; position < SIZE_UNITS.length && size > 1024; position++) {
        size = size / 1024;/*from   w w w .ja v  a2  s .c om*/
    }
    DecimalFormat df = new DecimalFormat("#,###.##");
    return df.format(size) + " " + SIZE_UNITS[position];
}

From source file:com.googlecode.starflow.engine.core.activity.ManualActivityType.java

public boolean isCompleteActivity(AbstractFlowEvent event, ActivityElement activityXml) {
    String rule = activityXml.getFinishRule();
    long activityInstId = ((ActivityFinishEvent) event).getActivityInst().getActivityInstId();
    boolean isComplete = false;

    if (Constants.ACT_WI_FINISHRULE_ALL.equalsIgnoreCase(rule)) {
        int unfinishCount = event.getWorkItemRep().getUnFinishedWorkItemCount(activityInstId);
        if (unfinishCount == 0)
            isComplete = true;/*from  w  w w.j  a v a2s  .c om*/
    } else if (Constants.ACT_WI_FINISHRULE_NUM.equalsIgnoreCase(rule)) {
        int ruleCount = activityXml.getFinishRquiredNum();
        int finishCount = event.getWorkItemRep().getFinishedWorkItemCount(activityInstId);
        if (ruleCount == finishCount)
            isComplete = true;
    } else if (Constants.ACT_WI_FINISHRULE_PERCENT.equalsIgnoreCase(rule)) {
        int total = event.getWorkItemRep().getWorkItemCount(activityInstId);
        int finishCount = event.getWorkItemRep().getFinishedWorkItemCount(activityInstId);

        double c = Double.parseDouble(String.valueOf(finishCount)) / total;

        DecimalFormat df1 = new DecimalFormat("##.0000"); // ##.0000%  ????2?0?
        String d = df1.format(c);

        double finishPercent = Double.parseDouble(d) * 100;

        double mustPercent = activityXml.getFinishRequiredPercent();
        if (finishPercent >= mustPercent)
            isComplete = true;
    }
    return isComplete;
}

From source file:gov.nih.nci.cabig.caaers.service.SafetyMonitoringServiceImplTest.java

private String format(Double d) {
    if (d == null)
        return null;
    DecimalFormat f = new DecimalFormat("##.00"); // this will help always keeps in two decimal places
    return f.format(d);
}

From source file:ANNFileDetect.EncogTestClass.java

private Double hashDbl(Double dbl) {
    DecimalFormat df = new DecimalFormat("#0.00000");
    String tmp = df.format(dbl);
    return Double.valueOf(tmp);

}

From source file:isl.FIMS.utils.Utils.java

public static String getDate() {

    Calendar cal = new GregorianCalendar(Locale.getDefault());
    DecimalFormat myformat = new DecimalFormat("00");

    // Get the components of the date
    // int era = cal.get(Calendar.ERA);               // 0=BC, 1=AD
    int year = cal.get(Calendar.YEAR); // 2002
    int month = cal.get(Calendar.MONTH) + 1; // 0=Jan, 1=Feb, ...
    int day = cal.get(Calendar.DAY_OF_MONTH); // 1...

    //   int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); // 1=Sunday, 2=Monday
    return myformat.format(day) + "-" + myformat.format(month) + "-" + year;
}

From source file:edu.nwpu.gemfire.monitor.service.MemberRegionsService.java

public ObjectNode execute(final HttpServletRequest request) throws Exception {

    // get cluster object
    Cluster cluster = Repository.get().getCluster();

    // json object to be sent as response
    ObjectNode responseJSON = mapper.createObjectNode();

    JsonNode requestDataJSON = mapper.readTree(request.getParameter("pulseData"));
    String memberName = requestDataJSON.get("MemberRegions").get("memberName").textValue();

    Cluster.Member clusterMember = cluster.getMember(StringUtils.makeCompliantName(memberName));

    if (clusterMember != null) {
        responseJSON.put("memberId", clusterMember.getId());
        responseJSON.put(this.NAME, clusterMember.getName());
        responseJSON.put("host", clusterMember.getHost());

        // member's regions
        Cluster.Region[] memberRegions = clusterMember.getMemberRegionsList();
        ArrayNode regionsListJson = mapper.createArrayNode();
        for (Cluster.Region memberRegion : memberRegions) {
            ObjectNode regionJSON = mapper.createObjectNode();
            regionJSON.put(this.NAME, memberRegion.getName());

            if (PulseConstants.PRODUCT_NAME_SQLFIRE
                    .equalsIgnoreCase(PulseController.getPulseProductSupport())) {
                // Convert region path to dot separated region path
                regionJSON.put("fullPath", StringUtils.getTableNameFromRegionName(memberRegion.getFullPath()));
            } else {
                regionJSON.put("fullPath", memberRegion.getFullPath());
            }/* ww w.  java 2  s  . com*/

            regionJSON.put("type", memberRegion.getRegionType());
            regionJSON.put("entryCount", memberRegion.getSystemRegionEntryCount());
            Long entrySize = memberRegion.getEntrySize();

            DecimalFormat form = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN_2);
            String entrySizeInMB = form.format(entrySize / (1024f * 1024f));

            if (entrySize < 0) {
                regionJSON.put(this.ENTRY_SIZE, this.VALUE_NA);
            } else {
                regionJSON.put(this.ENTRY_SIZE, entrySizeInMB);
            }
            regionJSON.put("scope", memberRegion.getScope());
            String diskStoreName = memberRegion.getDiskStoreName();
            if (StringUtils.isNotNullNotEmptyNotWhiteSpace(diskStoreName)) {
                regionJSON.put(this.DISC_STORE_NAME, diskStoreName);
                regionJSON.put(this.DISC_SYNCHRONOUS, memberRegion.isDiskSynchronous());
            } else {
                regionJSON.put(this.DISC_SYNCHRONOUS, this.VALUE_NA);
                regionJSON.put(this.DISC_STORE_NAME, "");
            }
            regionJSON.put("gatewayEnabled", memberRegion.getWanEnabled());

            regionsListJson.add(regionJSON);
        }
        responseJSON.put("memberRegions", regionsListJson);

        // response
        responseJSON.put("status", "Normal");

    }

    // Send json response
    return responseJSON;
}

From source file:com.wuliu.biz.orderdetail.engine.impl.OrderDetailMergeEngineImpl.java

@Override
public List<WuliuMergedOrderDetailModel> mergeOrderDetail(List<WuliuOrderDetailModel> wuliuOrderDetailModels,
        Long weightPrice, Long volumnPrice) {
    List<WuliuMergedOrderDetailModel> ret = new ArrayList<WuliuMergedOrderDetailModel>();

    if (CollectionUtils.isEmpty(wuliuOrderDetailModels)) {
        return ret;
    }/*  w w  w . j a  va  2  s . c o m*/

    WuliuMergedOrderDetailModel weightModel = null;
    WuliuMergedOrderDetailModel volumnModel = null;

    for (WuliuOrderDetailModel item : wuliuOrderDetailModels) {
        Long weightCost = getWeightCost(item, weightPrice);
        Long volumnCost = getVolumnCost(item, volumnPrice);
        if (weightCost * 1000000 > volumnCost) {
            if (weightModel == null) {
                weightModel = new WuliuMergedOrderDetailModel();
                weightModel.setType(WuliuMergedOrderDetailConst.TYPE_WEIGHT);
            }

            add(weightModel, item.getWeight(), 0L, weightCost, item.getCount());
        } else {
            if (volumnModel == null) {
                volumnModel = new WuliuMergedOrderDetailModel();
                volumnModel.setType(WuliuMergedOrderDetailConst.TYPE_VOLUMN);
            }

            add(volumnModel, 0, getVolumn(item), volumnCost, item.getCount());
        }
    }

    if (weightModel != null) {
        if (weightModel.getCost() % 100000L == 0) {
            weightModel.setCost(weightModel.getCost() / 100000);
        } else {
            weightModel.setCost((long) Math.ceil(weightModel.getCost() / 100000.0));
        }

        DecimalFormat df = new DecimalFormat("0.#");
        if (weightModel.getWeight() > 0) {
            weightModel.setWeightForDisplay(df.format(weightModel.getWeight() / 1000.0));
        }

        ret.add(weightModel);
    }

    if (volumnModel != null) {
        if (volumnModel.getCost() % 100000000000L == 0) {
            volumnModel.setCost(volumnModel.getCost() / 100000000000L);
        } else {
            volumnModel.setCost((long) Math.ceil(volumnModel.getCost() / 100000000000.0f));
        }
        ret.add(volumnModel);

        DecimalFormat df = new DecimalFormat("0.###");
        if (volumnModel.getVolumn() > 0) {
            volumnModel.setVolumnForDisplay(df.format(Math.ceil(volumnModel.getVolumn() / 1000000.0) / 1000.0));
        }
    }

    return ret;
}