List of usage examples for java.text DecimalFormat format
public final String format(double number)
From source file:net.ceos.project.poi.annotated.bean.ObjectMaskBuilder.java
/** * Transform Double values to validate.//w ww. j a va 2 s.c o m * * @param fieldName * @param value * @return */ private static Double transformValuesToValidate(String fieldName, Double value) { ObjectMask a = new ObjectMask(); try { Field f = a.getClass().getDeclaredField(fieldName); if (f.isAnnotationPresent(XlsElement.class)) { XlsElement xlsAnnotation = (XlsElement) f.getAnnotation(XlsElement.class); if (StringUtils.isNotBlank(xlsAnnotation.transformMask())) { DecimalFormat df = new DecimalFormat(xlsAnnotation.transformMask()); String formattedValue = df.format((Double) value); value = Double.valueOf(formattedValue.replace(",", ".")); } } } catch (NoSuchFieldException | SecurityException e) { e.printStackTrace(); } return value; }
From source file:net.nosleep.superanalyzer.util.Misc.java
private static String formatDuration(double value, String unitSingular, String unitPlural) { DecimalFormat decimalFormat = new DecimalFormat("0.0"); if (value > 1.0 && value < 1.01) return decimalFormat.format(value) + " " + capitalizeByLocale(unitSingular); else//from w ww . j av a2 s . c om return decimalFormat.format(value) + " " + capitalizeByLocale(unitPlural); }
From source file:Main.java
public static String formatBalance(BigDecimal balance, String curr, boolean round, DecimalFormat format) { DecimalFormatSymbols dfs = new DecimalFormatSymbols(); dfs.setDecimalSeparator(','); dfs.setGroupingSeparator(' '); DecimalFormat currency = format; if (currency == null) { if (!round) { currency = new DecimalFormat("#,##0.00 "); } else {/*from w ww.j ava 2 s .c o m*/ currency = new DecimalFormat("#,##0 "); } } currency.setDecimalFormatSymbols(dfs); return currency.format(balance.doubleValue()) + curr; }
From source file:juicebox.tools.utils.juicer.apa.APAPlotter.java
/** * Plot double centered at a point (rather than from the upper left corner as is the default) * * @param g2 graphics2D object/*from w ww. j a v a2s .c om*/ * @param value to be plotted * @param position for value to be centered at */ private static void drawCenteredDouble(Graphics2D g2, Double value, Point position) { DecimalFormat df = new DecimalFormat("0.000"); drawCenteredString(g2, df.format(value), position); }
From source file:com.kku.apps.pricesearch.util.Utils.java
public static String getPriceFromat(String price) { long num = Long.parseLong(price); final DecimalFormat df = new DecimalFormat("??###,###"); String value = df.format(num); return value; }
From source file:com.cedarsoft.io.LinkUtils.java
/** * Creates a temporary file//from w w w. j a v a 2s.c o m * * @param prefix the prefix * @param suffix the suffix * @param parentDir the parent dir * @return the created file */ @Nonnull public static File createTempFile(@Nonnull String prefix, @Nonnull String suffix, @Nullable File parentDir) { Random rand = new Random(); String parent = parentDir == null ? System.getProperty("java.io.tmpdir") : parentDir.getPath(); DecimalFormat fmt = new DecimalFormat("#####"); File result; do { result = new File(parent, prefix + fmt.format(Math.abs(rand.nextInt())) + suffix); } while (result.exists()); return result; }
From source file:ai.grakn.graql.internal.util.StringConverter.java
/** * @param value a value in the graph//from w w w.j a v a 2 s . com * @return the string representation of the value (using quotes if it is already a string) */ public static String valueToString(Object value) { if (value instanceof String) { return quoteString((String) value); } else if (value instanceof Double) { DecimalFormat df = new DecimalFormat("#", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); df.setMinimumFractionDigits(1); df.setMaximumFractionDigits(12); df.setMinimumIntegerDigits(1); return df.format(value); } else { return value.toString(); } }
From source file:com.bukanir.android.utils.Utils.java
public static String compareRelease(String torrentRelease, String subtitleRelease) { SimilarityStrategy strategy = new JaroWinklerStrategy(); StringSimilarityService service = new StringSimilarityServiceImpl(strategy); torrentRelease = torrentRelease.replace(".", " ").replace("-", " "); subtitleRelease = subtitleRelease.replace(".", " ").replace("-", " "); DecimalFormat df = new DecimalFormat("#.##"); double score = service.score(torrentRelease, subtitleRelease); return df.format(score); }
From source file:com.streamreduce.util.MessageUtils.java
public static String roundAndTruncate(double rawValue, int precision) { DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(precision); df.setMinimumFractionDigits(precision); df.setMinimumIntegerDigits(1);/*from w w w .jav a 2s . com*/ return df.format(rawValue); }
From source file:com.tinypace.mobistore.util.StringUtil.java
public static String formatMoney(BigDecimal d) { DecimalFormat mformat = new DecimalFormat(); mformat.setMaximumFractionDigits(2); mformat.setMinimumFractionDigits(2); mformat.setGroupingSize(20);/*from ww w .j a va 2s . c om*/ return mformat.format(d); }