List of usage examples for java.text NumberFormat setMaximumFractionDigits
public void setMaximumFractionDigits(int newValue)
From source file:org.sakaiproject.tool.assessment.ui.listener.util.ContextUtil.java
public static String getRoundedValue(Double orig, int maxdigit) { NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(maxdigit); String newscore = nf.format(orig); return newscore; }
From source file:info.curtbinder.farmgame.GameActivity.java
public static String getCurrencyFormattedString(int value) { NumberFormat nft = NumberFormat.getCurrencyInstance(Locale.getDefault()); nft.setMaximumFractionDigits(0); return nft.format(value); }
From source file:com.nextgis.mobile.forms.CompassFragment.java
public static String formatNumber(Object value, int max, int min) { NumberFormat f = NumberFormat.getInstance(); f.setMaximumFractionDigits(max); f.setMinimumFractionDigits(min);//from www . j av a 2 s .co m f.setGroupingUsed(false); try { return f.format(value); } catch (IllegalArgumentException e) { return "err"; } }
From source file:com.nextgis.maplibui.fragment.CompassFragment.java
public static String formatNumber(Object value, int max, int min) { NumberFormat f = NumberFormat.getInstance(); f.setMaximumFractionDigits(max); f.setMinimumFractionDigits(min);/*from w w w . j av a2 s . c o m*/ f.setGroupingUsed(false); try { return f.format(value); } catch (IllegalArgumentException e) { return e.getLocalizedMessage(); } }
From source file:com.glanznig.beepme.data.DataExporter.java
public static String getReadableFileSize(double size, int decimals) { if (size <= 0) { return "0 KB"; }//from w w w . j a v a 2s . co m final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" }; int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); NumberFormat numFormat = DecimalFormat.getInstance(); numFormat.setMaximumFractionDigits(decimals); return numFormat.format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; }
From source file:de.tor.tribes.util.html.FightReportHTMLToolTipGenerator.java
public static String buildToolTip(FightReport pReport) { String res = pTemplateData;/* ww w . j a va 2 s . com*/ String[] tables = buildUnitTables(pReport); SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy HH:mm:ss"); NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(0); res = res.replaceAll(WINNER_STRING, ((pReport.isWon() ? "Der Angreifer hat gewonnen" : "Der Verteidiger hat gewonnen"))); res = res.replaceAll(SEND_TIME, f.format(new Date(pReport.getTimestamp()))); res = res.replaceAll(ATTACKER_TABLE, tables[0]); res = res.replaceAll(DEFENDER_TABLE, tables[1]); res = res.replaceAll(MISC_TABLES, buildMiscTables(pReport)); res = res.replaceAll(LUCK_STRING, "Glück (aus Sicht des Angreifers)"); res = res.replaceAll(LUCK_BAR, buildLuckBar(pReport.getLuck())); res = res.replaceAll(MORAL, nf.format(pReport.getMoral()) + "%"); nf.setMinimumFractionDigits(1); nf.setMaximumFractionDigits(1); res = res.replaceAll(LUCK_NEG, ((pReport.getLuck() < 0) ? "<b>" + nf.format(pReport.getLuck()) + "%</b>" : "")); res = res.replaceAll(LUCK_POS, ((pReport.getLuck() >= 0) ? "<b>" + nf.format(pReport.getLuck()) + "%</b>" : "")); res = res.replaceAll(LUCK_ICON1, "<img src=\"" + ((pReport.getLuck() <= 0) ? FightReportHTMLToolTipGenerator.class.getResource("/res/rabe.png") : FightReportHTMLToolTipGenerator.class.getResource("/res/rabe_grau.png")) + "\"/>"); res = res.replaceAll(LUCK_ICON2, "<img src=\"" + ((pReport.getLuck() >= 0) ? FightReportHTMLToolTipGenerator.class.getResource("/res/klee.png") : FightReportHTMLToolTipGenerator.class.getResource("/res/klee_grau.png")) + "\"/>"); res = res.replaceAll(ATTACKER, StringEscapeUtils.escapeHtml(pReport.getAttacker().getName())); res = res.replaceAll(SOURCE, StringEscapeUtils.escapeHtml(pReport.getSourceVillage().getFullName())); res = res.replaceAll(DEFENDER, StringEscapeUtils.escapeHtml(pReport.getDefender().getName())); res = res.replaceAll(TARGET, StringEscapeUtils.escapeHtml(pReport.getTargetVillage().getFullName())); res = res.replaceAll(RAM_DAMAGE, ((pReport.wasWallDamaged()) ? "Wall beschädigt von Level <b>" + pReport.getWallBefore() + "</b> auf Level <b>" + pReport.getWallAfter() + "</b>" : "")); res = res.replaceAll(CATA_DAMAGE, ((pReport.wasBuildingDamaged()) ? pReport.getAimedBuilding() + " beschädigt von Level <b>" + pReport.getBuildingBefore() + "</b> auf Level <b>" + pReport.getBuildingAfter() + "</b>" : "")); res = res.replaceAll(SNOB_INFLUENCE, ((pReport.wasSnobAttack()) ? "Zustimmung gesunken von <b>" + pReport.getAcceptanceBefore() + "</b> auf <b>" + pReport.getAcceptanceAfter() + "</b>" : "")); return res; }
From source file:com.edgenius.core.util.FileUtil.java
/** * Check whether file is executable according to its extenstion and executable extension name list from Edgenius configuaration. * @param filename//from w ww .j av a 2s . co m * @return */ // public static boolean isExecutableFile(String filename){ // String extname = FileUtil.getFileExtension(filename); // log.debug("Check executable file for extension name " + extname); // // if(StringUtils.isBlank(extname)) // return false; // extname = "." + extname; // // String exeListStr = Global.ExecuteFileExt; // String[] extList = StringUtils.split(exeListStr, ','); // boolean executable = false; // for (String ext : extList) { // if(StringUtils.equalsIgnoreCase(ext, extname)){ // executable = true; // break; // } // } // // return executable; // } public static String convertHumanSize(long byteSize) { String unit = ""; float size = (float) byteSize; if (size > 1024) { size = size / 1024; unit = "K"; } if (size > 1024) { size = size / 1024; unit = "M"; } if (size > 1024) { size = size / 1024; unit = "G"; } NumberFormat format = NumberFormat.getNumberInstance(); format.setMaximumFractionDigits(1); String ret = format.format(size); return ret + unit; }
From source file:org.apache.nifi.schemaregistry.processors.CSVUtils.java
/** * According to the 1.7.7 spec If a logical type is invalid, for example a * decimal with scale greater than its precision,then implementations should * ignore the logical type and use the underlying Avro type. *//* www. ja v a 2 s . c o m*/ private static void normalizeNumberFormat(NumberFormat numberFormat, int scale, int precision) { if (scale < precision) { // write out with the specified precision and scale. numberFormat.setMaximumIntegerDigits(precision); numberFormat.setMaximumFractionDigits(scale); numberFormat.setMinimumFractionDigits(scale); } }
From source file:com.asburymotors.android.disneysocal.common.Utils.java
/** * Calculate distance between two LatLng points and format it nicely for * display. As this is a sample, it only statically supports metric units. * A production app should check locale and support the correct units. */// w w w. j a va2 s . c om public static String formatDistanceBetween(LatLng point1, LatLng point2) { if (point1 == null || point2 == null) { return null; } NumberFormat numberFormat = NumberFormat.getNumberInstance(); double distance = Math.round(SphericalUtil.computeDistanceBetween(point1, point2)); // Adjust to KM if M goes over 1000 (see javadoc of method for note // on only supporting metric) if (distance >= 1000) { numberFormat.setMaximumFractionDigits(1); return numberFormat.format(distance / 1000) + DISTANCE_KM_POSTFIX; } return numberFormat.format(distance) + DISTANCE_M_POSTFIX; }
From source file:edu.kit.dama.rest.util.RestClientUtils.java
/** * Build REST URL from a given pattern and its values. There is no check for * correct number of arguments. While generating URL all arguments will * encoded to be in a correct format. E.g.: 'stupid example' will be * transformed to 'stupid%20example'.//from w ww . java2s . c o m * * @param pattern URL with any number of place holders for arguments * @param arguments array of arguments for the place holders * @return encoded URL */ public static String encodeUrl(String pattern, Object... arguments) { List<Object> urlArg = new ArrayList<>(); for (Object arg : arguments) { if (arg == null) { throw new IllegalArgumentException("Null-values not supported for any element of 'arguments'."); } if (arg instanceof Number) { // everyting should work fine! NumberFormat instance = NumberFormat.getInstance(Locale.US); instance.setGroupingUsed(false); instance.setMaximumFractionDigits(9); String number = instance.format(arg); urlArg.add(number); } else if (arg instanceof String) { urlArg.add(encode((String) arg)); } else { LOGGER.warn("Uncovered argument type {}", arg); } } String returnValue = MessageFormat.format(pattern, urlArg.toArray()); LOGGER.debug("Final URL: {}", returnValue); return returnValue; }