List of usage examples for java.text DecimalFormat format
public final String format(double number)
From source file:com.jaspersoft.jasperserver.war.cascade.handlers.converters.DoubleDataConverter.java
@Override public String valueToString(Double value) { if (value == null) return ""; DecimalFormat df = (DecimalFormat) NumberFormat.getNumberInstance(LocaleContextHolder.getLocale()); df.setGroupingUsed(false);/*from w w w. ja va 2 s. c o m*/ df.setMaximumFractionDigits(Integer.MAX_VALUE); return df.format(value); }
From source file:com.jaspersoft.jasperserver.war.cascade.handlers.converters.FloatDataConverter.java
@Override public String valueToString(Float value) { if (value == null) return ""; DecimalFormat df = (DecimalFormat) NumberFormat.getNumberInstance(LocaleContextHolder.getLocale()); df.setGroupingUsed(false);//from ww w.j a v a 2 s. c om df.setMaximumFractionDigits(Integer.MAX_VALUE); return df.format(value); }
From source file:com.yunmel.syncretic.utils.io.IOUtils.java
/** * ????/* ww w . j av a 2s. c o m*/ * * @param fileSize ? * @return */ public static String getHumanSize(long fileSize) { // ? DecimalFormat df = new DecimalFormat("#.##"); String[] units = new String[] { "", "KB", "MB", "GB" }; int i = 0; double size = fileSize; while (size > 1024) { size = size / 1024; i++; } return (df.format(size)) + units[i]; }
From source file:com.mycompany.dvdmvc.controllers.DVDController.java
@RequestMapping("/searchAvg") public String findAvgAge(Map model) { double getAge = dao.findAvgAge(); DecimalFormat df = new DecimalFormat(""); String age = (df.format(getAge) + " years"); boolean avg = true; model.put("age", age); model.put("avg", avg); return "show"; }
From source file:com.cognitivabrasil.repositorio.data.entities.Files.java
@Transient public String getSizeFormatted() { String[] powerOfByte = { "Bytes", "KB", "MB", "GB", "TB" }; if (this.sizeInBytes == null || this.sizeInBytes <= 0) { return "Tamanho no definido"; }// ww w . j a va 2s. c o m int potencia = 0; int proxima; boolean testaPotenciaActual; boolean testaPotenciaSeguinte; do { proxima = potencia + 1; testaPotenciaActual = (Math.pow(2L, potencia * 10) <= this.sizeInBytes); testaPotenciaSeguinte = (this.sizeInBytes < Math.pow(2L, proxima * 10)); potencia++; } while (!(testaPotenciaActual && testaPotenciaSeguinte)); potencia--; DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.ENGLISH); otherSymbols.setDecimalSeparator(','); otherSymbols.setGroupingSeparator('.'); DecimalFormat myFormatter = new DecimalFormat("##.#", otherSymbols); return myFormatter.format(this.sizeInBytes / Math.pow(2L, potencia * 10)) + " " + powerOfByte[potencia]; }
From source file:com.nextgis.firereporter.ScanexNotificationItem.java
/** * Formats coordinate value to string based on output type (modified version * from Android API)/*w ww .j a va2 s . co m*/ */ public static String formatCoord(double coordinate, int outputType) { StringBuilder sb = new StringBuilder(); char endChar = DEGREE_CHAR; DecimalFormat df = new DecimalFormat("###.######"); if (outputType == Location.FORMAT_MINUTES || outputType == Location.FORMAT_SECONDS) { df = new DecimalFormat("##.###"); int degrees = (int) Math.floor(coordinate); sb.append(degrees); sb.append(DEGREE_CHAR); // degrees sign endChar = '\''; // minutes sign coordinate -= degrees; coordinate *= 60.0; if (outputType == Location.FORMAT_SECONDS) { df = new DecimalFormat("##.##"); int minutes = (int) Math.floor(coordinate); sb.append(minutes); sb.append('\''); // minutes sign endChar = '\"'; // seconds sign coordinate -= minutes; coordinate *= 60.0; } } sb.append(df.format(coordinate)); sb.append(endChar); return sb.toString(); }
From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.sign_browser.SignBrowserAdapter.java
@SuppressLint("RecyclerView") // Suggested improvement does not work. @Override//from ww w .j ava 2 s . c o m public void onBindViewHolder(final ViewHolder holder, final int position) { holder.imgSignIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { handleClickOnIconOrTxtSignName(dataSet.get(position)); } }); final String nameLocaleDe = dataSet.get(position).getNameLocaleDe(); holder.txtSignName.setText(nameLocaleDe); holder.txtSignName.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { handleClickOnIconOrTxtSignName(dataSet.get(position)); } }); final DecimalFormat decimalFormat = new DecimalFormat(" 0; -0"); holder.txtSignLearningProgress.setText(decimalFormat.format(dataSet.get(position).getLearningProgress())); holder.checkBoxStarred.setChecked(dataSet.get(position).isStarred()); holder.checkBoxStarred.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { handleClickOnCheckBoxStarred(dataSet.get(position)); } }); }
From source file:com.jennifer.ui.chart.brush.Brush.java
public String formatNumber(double value, DecimalFormat format) { return format.format(value); }
From source file:com.ewcms.publication.uri.UriRule.java
/** * ?//w ww. j a va 2s . c om * * @param value * @param patter ?? * @return ?? */ String formatValue(Object value, String patter) { logger.debug("Format type is {}", value.getClass().getName()); if (value instanceof Date) { if (patter == null || patter.length() == 0) { return DEFAULT_DATA_FORMAT.format(value); } else { DateFormat dateFormat = new SimpleDateFormat(patter); return dateFormat.format(value); } } else if (value instanceof Number) { if (patter == null || patter.length() == 0) { return DEFAULT_NUMBER_FORMAT.format(value); } else { DecimalFormat numberFormat = new DecimalFormat(patter); return numberFormat.format(value); } } else { return value.toString(); } }
From source file:com.pureinfo.srm.patent.action.PatentFeeListAction.java
private String getTotalFee() { QueryFilter filter = ((SearchForm) form).getQueryFilter(); filter.setSelect(" sum({this.supportNum}) as _SUM"); SearchForm thisform = (SearchForm) form; // 2. to render SQL List params = new ArrayList(); String strSQL = filter.toSQL(params); // 3. to execute the query IStatement query = null;// w ww.ja v a 2s . co m IObjects objs = null; double value = 0; try { IContentMgr mgr = ArkContentHelper.getContentMgrOf(thisform.getEntityMetadata().getEntityClass()); query = mgr.createQuery(strSQL, 1); filter.registerEntitiesInQuery(query); query.setParameters(0, params); query.setMaxSize(0); objs = query.executeQuery(false); DolphinObject obj = null; if ((obj = objs.next()) != null) { value = ((Number) obj.getProperty("_SUM")).doubleValue(); } } catch (Exception e) { logger.error("error to get total fee of patent.", e); } finally { params.clear(); if (query != null) query.clear(); if (objs != null) objs.clear(); } DecimalFormat f = new DecimalFormat("#.0"); return f.format(value); }