List of usage examples for java.text DecimalFormat DecimalFormat
public DecimalFormat(String pattern)
From source file:TempConverter3.java
public TempConverter3() { super();/*from w w w . ja v a2 s . c om*/ dff = new DecimalFormat("#0.0"); fp = new FieldPosition(NumberFormat.INTEGER_FIELD); }
From source file:Util.java
public static String[] getMemoryInfo() { double max = Runtime.getRuntime().maxMemory() / 1024; // maxMemory is the upper limit the jvm can use double allocated = Runtime.getRuntime().totalMemory() / 1024; // totalMemory the size of the current allocation // pool//from w ww. j ava 2 s. c om double nonAllocated = max - allocated; // non allocated memory till jvm limit double cached = Runtime.getRuntime().freeMemory() / 1024; // freeMemory the unused memory in the allocation pool double used = allocated - cached; // really used memory double useable = max - used; // allocated, but non-used and non-allocated memory DecimalFormat df = new DecimalFormat(" (0.0000'%')"); DecimalFormat df2 = new DecimalFormat(" # 'KB'"); return new String[] { // "+----", // "| Global Memory Informations at " + getRealTime().toString() + ":", // "| |", // "| Allowed Memory:" + df2.format(max), // "| |= Allocated Memory:" + df2.format(allocated) + df.format(allocated / max * 100), // "| |= Non-Allocated Memory:" + df2.format(nonAllocated) + df.format(nonAllocated / max * 100), // "| Allocated Memory:" + df2.format(allocated), // "| |= Used Memory:" + df2.format(used) + df.format(used / max * 100), // "| |= Unused (cached) Memory:" + df2.format(cached) + df.format(cached / max * 100), // "| Useable Memory:" + df2.format(useable) + df.format(useable / max * 100), // "+----" // }; }
From source file:com.wuliu.biz.util.WuliuOrderUtil.java
public static WuliuOrderModel convertToWuliuOrderModel(WuliuOrderDO wuliuOrderDO) { if (wuliuOrderDO == null) { return null; }/* ww w. j av a 2 s. co m*/ WuliuOrderModel ret = new WuliuOrderModel(); ret.setCarIndex(wuliuOrderDO.getCarIndex()); ret.setDaishouFee(wuliuOrderDO.getDaishouFee()); ret.setId(wuliuOrderDO.getId()); ret.setJiashouFee(wuliuOrderDO.getJiashouFee()); ret.setMemberId(wuliuOrderDO.getMemberId()); ret.setOrderDate(wuliuOrderDO.getOrderDate()); ret.setOrderNumber(wuliuOrderDO.getOrderNumber()); ret.setStatus(wuliuOrderDO.getStatus()); ret.setZhongzhuanFee(wuliuOrderDO.getZhongzhuanFee()); ret.setComments(wuliuOrderDO.getComments()); DecimalFormat df = new DecimalFormat("0.##"); if (ret.getZhongzhuanFee() != null) { ret.setZhongzhuanFeeForDisplay(df.format(ret.getZhongzhuanFee() / 100.0)); } if (ret.getDaishouFee() != null) { ret.setDaishouFeeForDisplay(df.format(ret.getDaishouFee() / 100.0)); } if (ret.getJiashouFee() != null) { ret.setJiashouFeeForDisplay(df.format(ret.getJiashouFee() / 100.0)); } return ret; }
From source file:com.cloudera.impala.common.PrintUtils.java
/** * Prints the given number of bytes in PB, TB, GB, MB, KB with 2 decimal points. * For example 5000 will be returned as 4.88KB. *//*from w ww .jav a2s .c o m*/ public static String printBytes(long bytes) { double result = bytes; // Avoid String.format() due to IMPALA-1572 which happens on JDK7 but not JDK6. if (bytes >= PETABYTE) return new DecimalFormat(".00PB").format(result / PETABYTE); if (bytes >= TERABYTE) return new DecimalFormat(".00TB").format(result / TERABYTE); if (bytes >= GIGABYTE) return new DecimalFormat(".00GB").format(result / GIGABYTE); if (bytes >= MEGABYTE) return new DecimalFormat(".00MB").format(result / MEGABYTE); if (bytes >= KILOBYTE) return new DecimalFormat(".00KB").format(result / KILOBYTE); return bytes + "B"; }
From source file:com.cssweb.quote.util.Utils.java
/** * ??/* w ww . j a va 2 s . c o m*/ * @param d * @param t * @return */ public static String dataFormation(double d, int t) { DecimalFormat df = null; switch (t) { case 0: df = new DecimalFormat("#.##"); df.setMinimumFractionDigits(0); return df.format(d); case 1: df = new DecimalFormat("#.##"); df.setMinimumFractionDigits(2); return df.format(d); case 2: df = new DecimalFormat("#.###"); df.setMinimumFractionDigits(3); return df.format(d); case 3: df = new DecimalFormat("#.####"); df.setMinimumFractionDigits(4); return df.format(d); case 4: df = new DecimalFormat("#.###%"); df.setMinimumFractionDigits(3); return df.format(d / 100); case 5: return String.valueOf((int) d); case 6: df = new DecimalFormat("#.##%"); df.setMinimumFractionDigits(2); return df.format(d); case 7: df = new DecimalFormat("#.#"); df.setMinimumFractionDigits(1); return df.format(d); case 8: df = new DecimalFormat("#.##%"); df.setMinimumFractionDigits(2); return df.format(d / 100); default: return "0"; } }
From source file:gov.nih.nci.rembrandt.web.helper.PCAAppletHelper.java
public static String generateParams(String sessionId, String taskId) { String htm = ""; DecimalFormat nf = new DecimalFormat("0.0000"); try {/*from w w w . j a va 2 s . co m*/ //retrieve the Finding from cache and build the list of PCAData points PrincipalComponentAnalysisFinding principalComponentAnalysisFinding = (PrincipalComponentAnalysisFinding) businessTierCache .getSessionFinding(sessionId, taskId); ArrayList<PrincipalComponentAnalysisDataPoint> pcaData = new ArrayList(); Collection<ClinicalFactorType> clinicalFactors = new ArrayList<ClinicalFactorType>(); List<String> sampleIds = new ArrayList(); Map<String, PCAresultEntry> pcaResultMap = new HashMap<String, PCAresultEntry>(); List<PCAresultEntry> pcaResults = principalComponentAnalysisFinding.getResultEntries(); for (PCAresultEntry pcaEntry : pcaResults) { sampleIds.add(pcaEntry.getSampleId()); pcaResultMap.put(pcaEntry.getSampleId(), pcaEntry); } Collection<SampleResultset> validatedSampleResultset = ClinicalDataValidator .getValidatedSampleResultsetsFromSampleIDs(sampleIds, clinicalFactors); if (validatedSampleResultset != null) { String id; PCAresultEntry entry; for (SampleResultset rs : validatedSampleResultset) { id = rs.getBiospecimen().getSpecimenName(); entry = pcaResultMap.get(id); PrincipalComponentAnalysisDataPoint pcaPoint = new PrincipalComponentAnalysisDataPoint(id, entry.getPc1(), entry.getPc2(), entry.getPc3()); String diseaseName = rs.getDisease().getValueObject(); if (diseaseName != null) { pcaPoint.setDiseaseName(diseaseName); } else { pcaPoint.setDiseaseName(DiseaseType.NON_TUMOR.name()); } GenderDE genderDE = rs.getGenderCode(); if (genderDE != null) { String gt = genderDE.getValueObject(); if (gt != null) { GenderType genderType = GenderType.valueOf(gt); if (genderType != null) { pcaPoint.setGender(genderType); } } } Long survivalLength = rs.getSurvivalLength(); if (survivalLength != null) { //survival length is stored in days in the DB so divide by 30 to get the //approx survival in months double survivalInMonths = survivalLength.doubleValue() / 30.0; pcaPoint.setSurvivalInMonths(survivalInMonths); } pcaData.add(pcaPoint); } } //make a hashmap // [key=group] hold the array of double[][]s HashMap<String, ArrayList> hm = new HashMap(); //now we should have a collection of PCADataPts double[][] pts = new double[pcaData.size()][3]; for (int i = 0; i < pcaData.size(); i++) { //just create a large 1 set for now //are we breaking groups by gender or disease? PrincipalComponentAnalysisDataPoint pd = pcaData.get(i); pts[i][0] = pd.getPc1value(); pts[i][1] = pd.getPc2value(); pts[i][2] = pd.getPc3value(); ArrayList<double[]> al; try { if (hm.containsKey(pd.getDiseaseName())) { //already has it, so add this one al = (ArrayList) hm.get(pd.getDiseaseName()); } else { al = new ArrayList(); hm.put(pd.getDiseaseName(), new ArrayList()); } if (!al.contains(pts[i])) { al.add(pts[i]); } hm.put(pd.getDiseaseName(), al); } catch (Exception e) { System.out.print(e.toString()); } } int r = hm.size(); if (r == 1) { } //hm should now contain a hashmap of all the disease groups //generate the param tags htm += "<param name=\"key\" value=\"" + taskId + "\" >\n"; htm += "<param name=\"totalPts\" value=\"" + pts.length + "\" >\n"; htm += "<param name=\"totalGps\" value=\"" + hm.size() + "\" >\n"; int ii = 0; for (Object k : hm.keySet()) { String key = k.toString(); //for each group Color diseaseColor = Color.GRAY; if (DiseaseType.valueOf(key) != null) { DiseaseType disease = DiseaseType.valueOf(key); diseaseColor = disease.getColor(); } ArrayList<double[]> al = hm.get(key); htm += "<param name=\"groupLabel_" + ii + "\" value=\"" + key + "\" >\n"; htm += "<param name=\"groupCount_" + ii + "\" value=\"" + al.size() + "\" >\n"; htm += "<param name=\"groupColor_" + ii + "\" value=\"" + diseaseColor.getRGB() + "\" >\n"; int jj = 0; for (double[] d : al) { String comm = nf.format(d[0]) + "," + nf.format(d[1]) + "," + nf.format(d[2]); String h = "<param name=\"pt_" + ii + "_" + jj + "\" value=\"" + comm + "\">\n"; htm += h; jj++; } ii++; } /* //for bulk rendering for(int i=0; i<pts.length; i++) { String comm = String.valueOf(pts[i][0]) + "," + String.valueOf(pts[i][1]) + "," + String.valueOf(pts[i][2]); String h = "<param name=\"pt_"+i+"\" value=\""+ comm +"\">\n"; //htm += h; } */ } //try catch (Exception e) { } return htm; }
From source file:com.bigml.histogram.SumResult.java
@Override public String toString() { return toJSON(new DecimalFormat(Histogram.DEFAULT_FORMAT_STRING)).toString(); }
From source file:DecimalFormatDemo.java
static public void customFormat(String pattern, double value) { DecimalFormat myFormatter = new DecimalFormat(pattern); String output = myFormatter.format(value); System.out.println(value + " " + pattern + " " + output); }
From source file:StringUtils.java
/** * Format a percentage for presentation to the user. * @param done the percentage to format (0.0 to 1.0) * @param digits the number of digits past the decimal point * @return a string representation of the percentage *///w ww . j a v a 2 s. c om public static String formatPercent(double done, int digits) { DecimalFormat percentFormat = new DecimalFormat("0.00%"); double scale = Math.pow(10.0, digits + 2); double rounded = Math.floor(done * scale); percentFormat.setDecimalSeparatorAlwaysShown(false); percentFormat.setMinimumFractionDigits(digits); percentFormat.setMaximumFractionDigits(digits); return percentFormat.format(rounded / scale); }
From source file:com.wuliu.biz.util.WuliuWholeOrderUtil.java
public static WuliuWholeOrderModel buildWholeModel(WuliuOrderModel wuliuOrderModel, List<WuliuOrderDetailModel> wuliuOrderDetailModels) { WuliuWholeOrderModel ret = new WuliuWholeOrderModel(); ret.setCarIndex(wuliuOrderModel.getCarIndex()); ret.setDaishouFee(wuliuOrderModel.getDaishouFee()); ret.setId(wuliuOrderModel.getId());//from w w w.j a v a 2 s. c om ret.setJiashouFee(wuliuOrderModel.getJiashouFee()); ret.setMemberId(wuliuOrderModel.getMemberId()); ret.setOrderDate(wuliuOrderModel.getOrderDate()); ret.setOrderNumber(wuliuOrderModel.getOrderNumber()); ret.setStatus(wuliuOrderModel.getStatus()); ret.setId(wuliuOrderModel.getId()); ret.setWuliuOrderDetailModels( WuliuWholeOrderDetailUtil.builduliuWholeDetailModelList(wuliuOrderDetailModels)); ret.setZhongzhuanFee(wuliuOrderModel.getZhongzhuanFee()); ret.setComments(wuliuOrderModel.getComments()); DecimalFormat df = new DecimalFormat("0.##"); if (ret.getZhongzhuanFee() != null) { ret.setZhongzhuanFeeForDisplay(df.format(ret.getZhongzhuanFee() / 100.0)); } if (ret.getDaishouFee() != null) { ret.setDaishouFeeForDisplay(df.format(ret.getDaishouFee() / 100.0)); } if (ret.getJiashouFee() != null) { ret.setJiashouFeeForDisplay(df.format(ret.getJiashouFee() / 100.0)); } int count = 0; if (CollectionUtils.isNotEmpty(wuliuOrderDetailModels)) { for (WuliuOrderDetailModel item : wuliuOrderDetailModels) { count += item.getCount(); } } ret.setOrderNumber(wuliuOrderModel.getOrderNumber()); return ret; }