List of usage examples for java.text DecimalFormat setGroupingUsed
@Override public void setGroupingUsed(boolean newValue)
From source file:org.mitre.math.linear.RandomMatrixExample.java
/** * //from w w w. ja va2 s . co m * @param m * @param width Column width. * @param digits Number of digits after the decimal. * @return */ public String matrix2String(RealMatrix m, int width, int digits) { DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(digits); format.setMinimumFractionDigits(digits); format.setGroupingUsed(false); StringBuilder output = new StringBuilder(); output.append('\n'); // start on new line. for (int i = 0; i < m.getRowDimension(); i++) { for (int j = 0; j < m.getColumnDimension(); j++) { String s = format.format(m.getEntry(i, j)); // format the number int padding = Math.max(1, width - s.length()); // At _least_ 1 space for (int k = 0; k < padding; k++) { output.append(' '); } output.append(s); } output.append('\n'); } output.append('\n'); // end with blank line. return output.toString(); }
From source file:org.clueminer.chameleon.GraphPropertyStore.java
public void printFancy(int w, int d) { DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1);/*from w ww . j av a 2s. c om*/ format.setMaximumFractionDigits(d); format.setMinimumFractionDigits(d); format.setGroupingUsed(false); printFancy(new PrintWriter(System.out, true), format, w + 2); }
From source file:com.netease.qa.emmagee.utils.CpuInfo.java
/** * reserve used ratio of process CPU and total CPU, meanwhile collect * network traffic.//from w ww . j av a 2s . c om * * @return network traffic ,used ratio of process CPU and total CPU in * certain interval */ public ArrayList<String> getCpuRatioInfo(String totalBatt, String currentBatt, String temperature, String voltage, String fps, boolean isRoot) { String heapData = ""; DecimalFormat fomart = new DecimalFormat(); fomart.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); fomart.setGroupingUsed(false); fomart.setMaximumFractionDigits(2); fomart.setMinimumFractionDigits(2); cpuUsedRatio.clear(); idleCpu.clear(); totalCpu.clear(); totalCpuRatio.clear(); readCpuStat(); try { String mDateTime2; Calendar cal = Calendar.getInstance(); if ((Build.MODEL.equals("sdk")) || (Build.MODEL.equals("google_sdk"))) { mDateTime2 = formatterFile.format(cal.getTime().getTime() + 8 * 60 * 60 * 1000); totalBatt = Constants.NA; currentBatt = Constants.NA; temperature = Constants.NA; voltage = Constants.NA; } else mDateTime2 = formatterFile.format(cal.getTime().getTime()); if (isInitialStatics) { preTraffic = trafficInfo.getTrafficInfo(); isInitialStatics = false; } else { lastestTraffic = trafficInfo.getTrafficInfo(); if (preTraffic == -1) traffic = -1; else { if (lastestTraffic > preTraffic) { traffic += (lastestTraffic - preTraffic + 1023) / 1024; } } preTraffic = lastestTraffic; Log.d(LOG_TAG, "lastestTraffic===" + lastestTraffic); Log.d(LOG_TAG, "preTraffic===" + preTraffic); StringBuffer totalCpuBuffer = new StringBuffer(); if (null != totalCpu2 && totalCpu2.size() > 0) { processCpuRatio = fomart.format(100 * ((double) (processCpu - processCpu2) / ((double) (totalCpu.get(0) - totalCpu2.get(0))))); for (int i = 0; i < (totalCpu.size() > totalCpu2.size() ? totalCpu2.size() : totalCpu.size()); i++) { String cpuRatio = "0.00"; if (totalCpu.get(i) - totalCpu2.get(i) > 0) { cpuRatio = fomart.format(100 * ((double) ((totalCpu.get(i) - idleCpu.get(i)) - (totalCpu2.get(i) - idleCpu2.get(i))) / (double) (totalCpu.get(i) - totalCpu2.get(i)))); } totalCpuRatio.add(cpuRatio); totalCpuBuffer.append(cpuRatio + Constants.COMMA); } } else { processCpuRatio = "0"; totalCpuRatio.add("0"); totalCpuBuffer.append("0,"); totalCpu2 = (ArrayList<Long>) totalCpu.clone(); processCpu2 = processCpu; idleCpu2 = (ArrayList<Long>) idleCpu.clone(); } // cpucsv for (int i = 0; i < getCpuNum() - totalCpuRatio.size() + 1; i++) { totalCpuBuffer.append("0.00,"); } long pidMemory = mi.getPidMemorySize(pid, context); String pMemory = fomart.format((double) pidMemory / 1024); long freeMemory = mi.getFreeMemorySize(context); String fMemory = fomart.format((double) freeMemory / 1024); String percent = context.getString(R.string.stat_error); if (totalMemorySize != 0) { percent = fomart.format(((double) pidMemory / (double) totalMemorySize) * 100); } if (isPositive(processCpuRatio) && isPositive(totalCpuRatio.get(0))) { String trafValue; // whether certain device supports traffic statics or not if (traffic == -1) { trafValue = Constants.NA; } else { trafValue = String.valueOf(traffic); } if (isRoot) { String[][] heapArray = MemoryInfo.getHeapSize(pid, context); heapData = heapArray[0][1] + "/" + heapArray[0][0] + Constants.COMMA + heapArray[1][1] + "/" + heapArray[1][0] + Constants.COMMA; } EmmageeService.bw.write(mDateTime2 + Constants.COMMA + ProcessInfo.getTopActivity(context) + Constants.COMMA + heapData + pMemory + Constants.COMMA + percent + Constants.COMMA + fMemory + Constants.COMMA + processCpuRatio + Constants.COMMA + totalCpuBuffer.toString() + trafValue + Constants.COMMA + totalBatt + Constants.COMMA + currentBatt + Constants.COMMA + temperature + Constants.COMMA + voltage + Constants.COMMA + fps + Constants.LINE_END); JSONObject jsonobj = new JSONObject(); JSONArray jsonarr = new JSONArray(); jsonarr.put(System.currentTimeMillis()); jsonarr.put(pMemory); jsonarr.put(percent); jsonarr.put(fMemory); jsonarr.put(processCpuRatio); jsonarr.put(totalCpuBuffer.toString().split(",")[0]); jsonarr.put(trafValue); jsonarr.put(totalBatt); jsonarr.put(currentBatt); jsonarr.put(temperature); jsonarr.put(voltage); jsonarr.put(fps); jsonobj.put("testSuitId", HttpUtils.testSuitId); jsonobj.put("data", jsonarr); HttpUtils.postAppPerfData(jsonobj.toString()); totalCpu2 = (ArrayList<Long>) totalCpu.clone(); processCpu2 = processCpu; idleCpu2 = (ArrayList<Long>) idleCpu.clone(); cpuUsedRatio.add(processCpuRatio); cpuUsedRatio.add(totalCpuRatio.get(0)); cpuUsedRatio.add(String.valueOf(traffic)); } } } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } return cpuUsedRatio; }
From source file:org.openehr.rm.datatypes.quantity.DvQuantity.java
/** * string form displayable for humans//from w w w .ja v a2 s . c om * * @return string presentation */ public String toString() { DecimalFormat format = new DecimalFormat(); format.setMinimumFractionDigits(precision); format.setMaximumFractionDigits(precision); DecimalFormatSymbols dfs = format.getDecimalFormatSymbols(); dfs.setDecimalSeparator(DECIMAL_SEPARATOR); format.setDecimalFormatSymbols(dfs); format.setGroupingUsed(false); String tmp = format.format(magnitude) + (StringUtils.isEmpty(getUnits()) ? "" : "," + getUnits()); return tmp; }
From source file:org.glom.web.server.ReportGenerator.java
/** * @param x//w w w . j a v a 2 s . c o m * @param libglomLayoutItemField * @return */ private JRDesignTextField createFieldValueElement(final Position pos, final LayoutItemField libglomLayoutItemField) { final JRDesignTextField textField = new JRDesignTextField(); // Make sure this field starts at the right of the previous field, // because JasperReports uses absolute positioning. textField.setY(pos.y); textField.setX(pos.x); textField.setWidth(width); // No data will be shown without this. // This only stretches vertically, but that is better than // nothing. textField.setStretchWithOverflow(true); textField.setHeight(height); // We must specify _some_ height. final JRDesignExpression expression = createFieldExpression(libglomLayoutItemField); textField.setExpression(expression); if (libglomLayoutItemField.getGlomType() == GlomFieldType.TYPE_NUMERIC) { // Numeric formatting: final Formatting formatting = libglomLayoutItemField.getFormattingUsed(); final NumericFormat numericFormat = formatting.getNumericFormat(); final DecimalFormat format = new DecimalFormat(); format.setMaximumFractionDigits(numericFormat.getDecimalPlaces()); format.setGroupingUsed(numericFormat.getUseThousandsSeparator()); // TODO: Use numericFormat.get_currency_symbol(), possibly via format.setCurrency(). textField.setPattern(format.toPattern()); } else if (libglomLayoutItemField.getGlomType() == GlomFieldType.TYPE_DATE) { // Date formatting // TODO: Use a 4-digit-year short form, somehow. try // We use a try block because getDateInstance() is not guaranteed to return a SimpleDateFormat. { final SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, Locale.ROOT); textField.setPattern(format.toPattern()); } catch (final Exception ex) { Log.info("ReportGenerator: The cast of SimpleDateFormat failed."); } } else if (libglomLayoutItemField.getGlomType() == GlomFieldType.TYPE_TIME) { // Time formatting try // We use a try block because getDateInstance() is not guaranteed to return a SimpleDateFormat. { final SimpleDateFormat format = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT, Locale.ROOT); textField.setPattern(format.toPattern()); } catch (final Exception ex) { Log.info("ReportGenerator: The cast of SimpleDateFormat failed."); } } return textField; }
From source file:org.tdar.struts.action.TdarActionSupport.java
public String getMapDefaultLat() { DecimalFormat latlong = new DecimalFormat("0.00"); latlong.setGroupingUsed(false); return latlong.format(getTdarConfiguration().getMapDefaultLat()); }
From source file:org.tdar.struts.action.TdarActionSupport.java
public String getMapDefaultLng() { DecimalFormat latlong = new DecimalFormat("0.00"); latlong.setGroupingUsed(false); return latlong.format(getTdarConfiguration().getMapDefaultLng()); }
From source file:org.jpos.qi.QIEntityView.java
public void formatGrid() { setGridGetters();// w w w .ja va 2s. co m //Delete not visible columns //Use columnId as caption //Set sorting for every column. DecimalFormat nf = new DecimalFormat(); nf.setGroupingUsed(false); Iterator<Grid.Column> it = grid.getColumns().iterator(); while (it.hasNext()) { Grid.Column c = it.next(); String columnId = c.getId(); if (!Arrays.asList(getVisibleColumns()).contains(columnId)) { grid.removeColumn(columnId); } else { c.setCaption(getCaptionFromId("column." + columnId)).setSortProperty(columnId).setSortable(true) .setHidable(true); ViewConfig.FieldConfig config = viewConfig.getFields().get(c.getId()); if (config != null) { if (config.getExpandRatio() != -1) c.setExpandRatio(config.getExpandRatio()); } c.setStyleGenerator(obj -> { Object value = c.getValueProvider().apply(obj); if (value instanceof BigDecimal && !c.getId().equals("id")) { return "align-right"; } return null; }); } } //fix for when a manual resize is done, the last column takes the empty space. grid.addColumnResizeListener(event -> { int lastColumnIndex = grid.getColumns().size() - 1; ((Grid.Column) grid.getColumns().get(lastColumnIndex)).setWidth(1500); }); grid.setSizeFull(); }
From source file:com.physphil.android.unitconverterultimate.fragments.ConversionFragment.java
/** * Get DecimalFormat used to format result * * @return DecimalFormat//w ww . ja v a 2s .c om */ private DecimalFormat getDecimalFormat() { DecimalFormat formatter = new DecimalFormat(); //Set maximum number of decimal places formatter.setMaximumFractionDigits(mPrefs.getNumberDecimals()); //Set group and decimal separators DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols(); symbols.setDecimalSeparator(mPrefs.getDecimalSeparator().charAt(0)); String groupSeparator = mPrefs.getGroupSeparator(); boolean isSeparatorUsed = !groupSeparator.equals(getString(R.string.group_separator_none)); formatter.setGroupingUsed(isSeparatorUsed); if (isSeparatorUsed) { symbols.setGroupingSeparator(groupSeparator.charAt(0)); } formatter.setDecimalFormatSymbols(symbols); return formatter; }
From source file:org.talend.dataprep.transformation.actions.math.ChangeNumberFormat.java
/** * Return the custom format out of the parameters. * * @param parameters the action parameters. * @return the custom format out of the parameters. *//*w w w . j a va 2 s . c o m*/ private NumberFormat getCustomFormat(Map<String, String> parameters) { final DecimalFormat decimalFormat = new DecimalFormat(parameters.get(TARGET_PATTERN + "_" + CUSTOM)); DecimalFormatSymbols decimalFormatSymbols = decimalFormat.getDecimalFormatSymbols(); String decimalSeparator = getCustomizableParam(TARGET + DECIMAL + SEPARATOR, parameters); if (!StringUtils.isEmpty(decimalSeparator)) { decimalFormatSymbols.setDecimalSeparator(decimalSeparator.charAt(0)); } String groupingSeparator = getCustomizableParam(TARGET + GROUPING + SEPARATOR, parameters); if (StringUtils.isEmpty(groupingSeparator) || groupingSeparator.equals(decimalSeparator)) { decimalFormat.setGroupingUsed(false); } else { decimalFormatSymbols.setGroupingSeparator(groupingSeparator.charAt(0)); } decimalFormat.setDecimalFormatSymbols(decimalFormatSymbols); return decimalFormat; }