List of usage examples for java.text NumberFormat getNumberInstance
public static NumberFormat getNumberInstance(Locale inLocale)
From source file:com.limegroup.gnutella.gui.GUIUtils.java
static void resetLocale() { NUMBER_FORMAT0 = NumberFormat.getNumberInstance(GUIMediator.getLocale()); NUMBER_FORMAT0.setMaximumFractionDigits(0); NUMBER_FORMAT0.setMinimumFractionDigits(0); NUMBER_FORMAT0.setGroupingUsed(true); NUMBER_FORMAT1 = NumberFormat.getNumberInstance(GUIMediator.getLocale()); NUMBER_FORMAT1.setMaximumFractionDigits(1); NUMBER_FORMAT1.setMinimumFractionDigits(1); NUMBER_FORMAT1.setGroupingUsed(true); DATETIME_FORMAT = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, GUIMediator.getLocale());// w w w .ja v a2 s.c om FULL_DATETIME_FORMAT = new SimpleDateFormat("EEE, MMM. d, yyyy h:mm a", GUIMediator.getLocale()); GENERAL_UNIT_KILOBYTES = I18n.tr("KB"); GENERAL_UNIT_MEGABYTES = I18n.tr("MB"); GENERAL_UNIT_GIGABYTES = I18n.tr("GB"); GENERAL_UNIT_TERABYTES = I18n.tr("TB"); GENERAL_UNIT_KBPSEC = I18n.tr("KB/s"); }
From source file:org.asqatasun.webapp.command.factory.ChangeTestWeightCommandFactory.java
/** * //from w w w . j ava 2s . c o m * @param user * @param locale * @param testList * @param referentialKey * @return * an initialised instance of ChangeTestWeightCommand */ public ChangeTestWeightCommand getChangeTestWeightCommand(User user, Locale locale, Collection<Test> testList, String referentialKey) { Map<String, String> userTestWeight = new HashMap<String, String>(); NumberFormat nf = NumberFormat.getNumberInstance(locale); nf.setMinimumFractionDigits(1); nf.setMaximumFractionDigits(1); nf.setMaximumIntegerDigits(1); nf.setMinimumIntegerDigits(1); for (OptionElement oe : optionElementDataService.getOptionElementFromUserAndFamilyCode(user, referentialKey + "_" + optionFamilyCodeStr)) { userTestWeight.put(oe.getOption().getCode(), nf.format(Double.valueOf(oe.getValue()))); } for (Test test : testList) { if (!userTestWeight.containsKey(test.getCode())) { userTestWeight.put(test.getCode(), ""); } } ChangeTestWeightCommand changeTestWeightCommand = new ChangeTestWeightCommand(); changeTestWeightCommand.setTestWeightMap(userTestWeight); return changeTestWeightCommand; }
From source file:com.skubit.satoshidice.placebet.PlaceBetFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true);// ww w. j av a 2s . c om mApiRestService = new UserApiService(this.getActivity()).getRestService(); NumberFormat nf = NumberFormat.getNumberInstance(Locale.getDefault()); mPayoutFormat = (DecimalFormat) nf; mPayoutFormat.setDecimalSeparatorAlwaysShown(true); mPayoutFormat.setMaximumFractionDigits(5); mPayoutFormat.setMinimumFractionDigits(0); NumberFormat nf1 = NumberFormat.getNumberInstance(Locale.getDefault()); mWinFormat = (DecimalFormat) nf1; mWinFormat.setDecimalSeparatorAlwaysShown(true); mWinFormat.setMaximumFractionDigits(3); mWinFormat.setMinimumFractionDigits(3); }
From source file:com.expressui.core.view.field.format.DefaultFormats.java
/** * Gets number format, NumberFormat.getNumberInstance(), using current user's locale. * * @return number format with current user's locale *//*w ww. j av a2s . c o m*/ public PropertyFormatter getNumberFormat() { return new JDKBridgePropertyFormatter( NumberFormat.getNumberInstance(MainApplication.getInstance().getLocale())); }
From source file:gob.dp.simco.comun.FunctionUtil.java
public static String formateaDecimal(double numero) { if (numero > 0) { Locale locale = new Locale("en", "UK"); String pattern = "###,###.##"; DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getNumberInstance(locale); decimalFormat.applyPattern(pattern); String format = decimalFormat.format(numero); return format; }/*from w ww . ja v a 2s .c o m*/ return null; }
From source file:de.awtools.basic.AWTools.java
/** * Wandelt einen double Wert in einen String anhand des angegebenen Patterns. * Siehe zu diesem Thema auch im Java-Tutorial bzw. API. * * <p>/* w w w . j a va 2 s.c om*/ * Apply the given pattern to this Format object. A pattern is a short-hand * specification for the various formatting properties. These properties can * also be changed individually through the various setter methods. There * is no limit to integer digits set by this routine, since that is the * typical end-user desire; use setMaximumInteger if you want to set a * real value. For negative numbers, use a second pattern, separated by a semicolon * </p> * <p> * Example "#,#00.0#" -> 1,234.56 * This means a minimum of 2 integer digits, 1 fraction digit, and a maximum * of 2 fraction digits. * </p> * <p> * Example: "#,#00.0#;(#,#00.0#)" for negatives in parentheses. * In negative patterns, the minimum and maximum counts are ignored; these * are presumed to be set in the positive pattern. * </p> * * @param value Der zu konvertierende Wert. * @param pattern Das zu verwendende Pattern. * @param locale Das zu verwendende Locale. * @return Formatiert einen <code>double</code>. */ public static String toString(final double value, String pattern, final Locale locale) { NumberFormat nf = NumberFormat.getNumberInstance(locale); DecimalFormat df = (DecimalFormat) nf; df.applyPattern(pattern); return df.format(value); }
From source file:com.stanley.captioner.MainFrame.java
private Object[] getVideoInfo(File file) { String path = file.getAbsolutePath(); Converter converter = new Converter(); FFprobe ffprobe = null;/* w ww .j a v a2 s.c o m*/ try { ffprobe = new FFprobe(converter.getFFprobePath()); } catch (IOException e) { System.out.println("Failed to find ffprobe."); } FFmpegProbeResult probeResult = null; try { probeResult = ffprobe.probe(path); } catch (IOException e) { System.out.println("Failed to probe video file."); } FFmpegFormat format = probeResult.getFormat(); FFmpegStream stream = probeResult.getStreams().get(0); String type = FilenameUtils.getExtension(path).toUpperCase(); String size = NumberFormat.getNumberInstance(Locale.US).format(file.length() / 1000) + " KB"; long millis = stream.duration_ts * 1000; TimeZone tz = TimeZone.getTimeZone("UTC"); SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss"); df.setTimeZone(tz); String duration = df.format(new Date(millis)); return new Object[] { format.filename, type, size, duration, stream.codec_name, stream.width, stream.height }; }
From source file:com.expressui.core.view.field.format.DefaultFormats.java
/** * Gets number format, NumberFormat.getNumberInstance(), using current user's locale. * * @param maximumFractionDigits maximum number of fraction digits * @param defaultValueWhenEmpty when parsing Strings, returns this value when String is empty * @return default number format/*www. j a v a 2 s . c o m*/ */ public PropertyFormatter getNumberFormat(int maximumFractionDigits, Object defaultValueWhenEmpty) { NumberFormat numberFormat = NumberFormat.getNumberInstance(MainApplication.getInstance().getLocale()); numberFormat.setMaximumFractionDigits(maximumFractionDigits); return new JDKBridgePropertyFormatter(numberFormat, defaultValueWhenEmpty); }
From source file:chibi.gemmaanalysis.CorrelationAnalysisCLI.java
@Override protected Exception doWork(String[] args) { Exception exc = processCommandLine(args); if (exc != null) { return exc; }//from w w w. j a v a 2s . com Collection<Gene> queryGenes, targetGenes; try { queryGenes = getQueryGenes(); targetGenes = getTargetGenes(); } catch (IOException e) { return e; } // calculate matrices CoexpressionMatrices matrices = coexpressionAnalysisService.calculateCoexpressionMatrices( expressionExperiments, queryGenes, targetGenes, filterConfig, CorrelationMethod.SPEARMAN); DenseDouble3dMatrix<Gene, Gene, BioAssaySet> correlationMatrix = matrices.getCorrelationMatrix(); // DenseDoubleMatrix3DNamed sampleSizeMatrix = matrices // .getSampleSizeMatrix(); // DoubleMatrixNamed maxCorrelationMatrix = coexpressionAnalysisService // .getMaxCorrelationMatrix(correlationMatrix, kMax); // DoubleMatrixNamed pValMatrix = coexpressionAnalysisService // .calculateMaxCorrelationPValueMatrix(maxCorrelationMatrix, // kMax, ees); // DoubleMatrixNamed effectSizeMatrix = coexpressionAnalysisService // .calculateEffectSizeMatrix(correlationMatrix, sampleSizeMatrix); // get row/col name maps Map<Gene, String> geneNameMap = matrices.getGeneNameMap(); Map<ExpressionExperiment, String> eeNameMap = matrices.getEeNameMap(); DecimalFormat formatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US); formatter.applyPattern("0.0000"); DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols(); symbols.setNaN("NaN"); formatter.setDecimalFormatSymbols(symbols); try { MatrixWriter<Gene, Gene> matrixOut; matrixOut = new MatrixWriter<Gene, Gene>(outFilePrefix + ".corr.txt", formatter); matrixOut.setSliceNameMap(eeNameMap); matrixOut.setRowNameMap(geneNameMap); matrixOut.setColNameMap(geneNameMap); matrixOut.writeMatrix(correlationMatrix, false); try (PrintWriter out = new PrintWriter(new FileWriter(outFilePrefix + ".corr.row_names.txt"));) { List<Gene> rows = correlationMatrix.getRowNames(); for (Gene row : rows) { out.println(row); } } try (PrintWriter out = new PrintWriter(new FileWriter(outFilePrefix + ".corr.col_names.txt"));) { Collection<BioAssaySet> cols = correlationMatrix.getSliceNames(); for (BioAssaySet bas : cols) { ExpressionExperiment ee = (ExpressionExperiment) bas; out.println(ee.getShortName()); } } } catch (IOException e) { return e; } // out = new MatrixWriter(outFilePrefix + ".max_corr.txt", formatter, // geneNameMap, geneNameMap); // out.writeMatrix(maxCorrelationMatrix, true); // out.close(); // // out = new MatrixWriter(outFilePrefix + ".max_corr.pVal.txt", // formatter, geneNameMap, geneNameMap); // out.writeMatrix(pValMatrix, true); // out.close(); // // out = new MatrixWriter(outFilePrefix + ".effect_size.txt", // formatter, geneNameMap, geneNameMap); // out.writeMatrix(effectSizeMatrix, true); // out.close(); return null; }
From source file:playground.jbischoff.carsharing.data.VBBRouteCatcher.java
private void run(Coord from, Coord to, long departureTime) { Locale locale = new Locale("en", "UK"); String pattern = "###.000000"; DecimalFormat df = (DecimalFormat) NumberFormat.getNumberInstance(locale); df.applyPattern(pattern);// w ww . ja v a2s.co m // Construct data //X&Y coordinates must be exactly 8 digits, otherwise no proper result is given. They are swapped (x = long, y = lat) //Verbindungen 1-n bekommen; Laufweg, Reisezeit & Umstiege ermitteln String text = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" + "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" + "<ReqC accessId=\"JBischoff2486b558356fa9b81b1rzum\" ver=\"1.1\" requestId=\"7\" prod=\"SPA\" lang=\"DE\">" + "<ConReq>" + "<ReqT date=\"" + VBBDAY.format(departureTime) + "\" time=\"" + VBBTIME.format(departureTime) + "\">" + "</ReqT>" + "<RFlags b=\"0\" f=\"1\" >" + "</RFlags>" + "<Start>" + "<Coord name=\"START\" x=\"" + df.format(from.getY()).replace(".", "") + "\" y=\"" + df.format(from.getX()).replace(".", "") + "\" type=\"WGS84\"/>" + "<Prod prod=\"1111000000000000\" direct=\"0\" sleeper=\"0\" couchette=\"0\" bike=\"0\"/>" + "</Start>" + "<Dest>" + "<Coord name=\"ZIEL\" x=\"" + df.format(to.getY()).replace(".", "") + "\" y=\"" + df.format(to.getX()).replace(".", "") + "\" type=\"WGS84\"/>" + "</Dest>" + "</ConReq>" + "</ReqC>"; PostMethod post = new PostMethod("http://demo.hafas.de/bin/pub/vbb/extxml.exe/"); post.setRequestBody(text); post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1"); HttpClient httpclient = new HttpClient(); try { int result = httpclient.executeMethod(post); // Display status code // System.out.println("Response status code: " + result); // Display response // System.out.println("Response body: "); // System.out.println(post.getResponseBodyAsString()); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(post.getResponseBodyAsStream()); if (writeOutput) { BufferedWriter writer = IOUtils.getBufferedWriter(filename); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //initialize StreamResult with File object to save to file StreamResult res = new StreamResult(writer); DOMSource source = new DOMSource(document); transformer.transform(source, res); writer.flush(); writer.close(); } Node connectionList = document.getFirstChild().getFirstChild().getFirstChild(); NodeList connections = connectionList.getChildNodes(); int amount = connections.getLength(); for (int i = 0; i < amount; i++) { Node connection = connections.item(i); Node overview = connection.getFirstChild(); ; while (!overview.getNodeName().equals("Overview")) { overview = overview.getNextSibling(); } System.out.println(overview.getChildNodes().item(3).getTextContent()); int transfers = Integer.parseInt(overview.getChildNodes().item(3).getTextContent()); String time = overview.getChildNodes().item(4).getFirstChild().getTextContent().substring(3); System.out.println(time); Date rideTime = VBBDATE.parse(time); int seconds = rideTime.getHours() * 3600 + rideTime.getMinutes() * 60 + rideTime.getSeconds(); System.out.println(seconds + "s; transfers: " + transfers); if (seconds < this.bestRideTime) { this.bestRideTime = seconds; this.bestTransfers = transfers; } } } catch (Exception e) { this.bestRideTime = -1; this.bestTransfers = -1; } finally { // Release current connection to the connection pool // once you are done post.releaseConnection(); post.abort(); } }