List of usage examples for java.text DecimalFormat setDecimalFormatSymbols
public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols)
From source file:LPGoogleFunctions.LPGoogleFunctions.java
/** * Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic coordinates * (like latitude 37.423021 and longitude -122.083739), which you can use to place markers or position the map. * @param address - The location (such as 40.457375,-80.009353). * @param filterComponents - A component filter for which you wish to obtain a geocode. * The components filter will also be accepted as an optional parameter if an address is provided. See LPGeocodingFilter.h for components. * @param responseHandler/* w ww . j a v a 2s .c o m*/ * @Override public void willLoadGeocoding() * @Override public void didLoadGeocoding(LPGeocodingResults geocodingResults) * @Override public void errorLoadingGeocoding(LPGoogleStatus status) */ public void loadGeocodingForLocation(LPLocation location, ArrayList<LPGeocodingFilter> filterComponents, final GeocodingListener responseHandler) { if (responseHandler != null) responseHandler.willLoadGeocoding(); RequestParams parameters = new RequestParams(); DecimalFormatSymbols separator = new DecimalFormatSymbols(); separator.setDecimalSeparator('.'); DecimalFormat coordinateDecimalFormat = new DecimalFormat("##.######"); coordinateDecimalFormat.setDecimalFormatSymbols(separator); if (location != null) parameters.put("latlng", String.format("%s,%s", coordinateDecimalFormat.format(location.latitude), coordinateDecimalFormat.format(location.longitude))); parameters.put("sensor", this.sensor ? "true" : "false"); parameters.put("language", this.languageCode); //COMPONENTS FILTER if (filterComponents != null) { if (filterComponents.size() > 0) { StringBuilder comString = new StringBuilder("components="); for (int i = 0; i < filterComponents.size(); i++) { LPGeocodingFilter filter = filterComponents.get(i); comString.append(String.format("%s:%s", LPGeocodingFilter.getGeocodingFilter(filter.filter), filter.value)); } } } this.client.get(googleAPIGeocodingURL, parameters, new AsyncHttpResponseHandler() { @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { if (responseHandler != null) responseHandler.errorLoadingGeocoding(LPGoogleStatus.LPGoogleStatusUnknownError); } @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { try { String response = new String(arg2, "UTF-8"); JSONObject object = new JSONObject(response); LPGeocodingResults geocodingResults = new LPGeocodingResults(object); LPGoogleStatus status = LPGoogleFunctions .getGoogleStatusFromString(geocodingResults.statusCode); if (status == LPGoogleStatus.LPGoogleStatusOK) { if (responseHandler != null) responseHandler.didLoadGeocoding(geocodingResults); } else { if (responseHandler != null) responseHandler.errorLoadingGeocoding(status); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); if (responseHandler != null) responseHandler.errorLoadingGeocoding(LPGoogleStatus.LPGoogleStatusUnknownError); } catch (JSONException e) { e.printStackTrace(); if (responseHandler != null) responseHandler.errorLoadingGeocoding(LPGoogleStatus.LPGoogleStatusUnknownError); } } }); }
From source file:com.tonbeller.jpivot.chart.ChartComponent.java
/** * Get cell value as a Number. Parses the cell value string * using the locale set in this.locale./*w w w . j a va 2 s . com*/ * @param cell * @return value as Number (can be null) */ private Number getNumberValue(Cell cell) { //**** HACK AR 2004.01.10 //String value = cell.getFormattedValue(); Object value = cell.getValue(); DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale); DecimalFormat formatter = new DecimalFormat(); formatter.setDecimalFormatSymbols(dfs); Number number = null; try { number = (Number) value; //number = formatter.parse(value, new ParsePosition(0)); } catch (Exception e) { number = null; } return number; }
From source file:LPGoogleFunctions.LPGoogleFunctions.java
/** * The Google Directions API is a service that calculates directions between locations using an HTTP request. * You can search for directions for several modes of transportation, include transit, driving, walking or cycling. * Directions may specify origins, destinations and waypoints either as text strings (e.g. "Chicago, IL" or "Darwin, NT, Australia") or as latitude/longitude coordinates. * The Directions API can return multi-part directions using a series of waypoints. * @param origin - The latitude/longitude value from which you wish to calculate directions. * @param destination - The latitude/longitude value from which you wish to calculate directions. * @param travelMode - Specifies the mode of transport to use when calculating directions. If you set the mode to "transit" you must also specify either a departure time or an arrival time. * @param avoid - Indicates that the calculated route(s) should avoid the indicated features. * @param unit - Specifies the unit system to use when displaying results. * @param alternatives - If set to true, specifies that the Directions service may provide more than one route alternative in the response. Note that providing route alternatives may increase the response time from the server. * @param departureTimeSeconds - Specifies the desired time of departure. * @param arrivalTimeSeconds - Specifies the desired time of arrival. * @param waypoints - Specifies an array of waypoints. Waypoints alter a route by routing it through the specified location(s). A waypoint is specified as either a latitude/longitude coordinate or as an address which will be geocoded. * @param responseHandler//w w w. j a v a2 s .c o m * @Override public void willLoadDirections() * @Override public void didLoadDirections(LPDirections directions) * @Override public void errorLoadingDirections(LPGoogleStatus status) */ public void loadDirectionsForOrigin(LPLocation origin, LPLocation destination, final LPGoogleDirectionsTravelMode travelMode, LPGoogleDirectionsAvoid avoid, LPGoogleDirectionsUnit unit, boolean alternatives, long departureTimeSeconds, long arrivalTimeSeconds, ArrayList<LPWaypoint> waypoints, final DirectionsListener responseHandler) { if (responseHandler != null) responseHandler.willLoadDirections(); RequestParams parameters = new RequestParams(); DecimalFormatSymbols separator = new DecimalFormatSymbols(); separator.setDecimalSeparator('.'); DecimalFormat coordinateDecimalFormat = new DecimalFormat("##.######"); coordinateDecimalFormat.setDecimalFormatSymbols(separator); if (origin != null) parameters.put("origin", String.format("%s,%s", coordinateDecimalFormat.format(origin.latitude), coordinateDecimalFormat.format(origin.longitude))); if (destination != null) parameters.put("destination", String.format("%s,%s", coordinateDecimalFormat.format(destination.latitude), coordinateDecimalFormat.format(destination.longitude))); parameters.put("sensor", this.sensor ? "true" : "false"); parameters.put("language", this.languageCode); if (travelMode != null) { parameters.put("mode", LPStep.getDirectionsTravelMode(travelMode)); } if (avoid != null) { parameters.put("avoid", LPDirections.getDirectionsAvoid(avoid)); } if (unit != null) { parameters.put("units", LPDirections.getDirectionsUnit(unit)); } parameters.put("alternatives", alternatives ? "true" : "false"); if (departureTimeSeconds > 0) { parameters.put("departure_time", String.valueOf(departureTimeSeconds)); } if (arrivalTimeSeconds > 0) { parameters.put("arrival_time", String.valueOf(arrivalTimeSeconds)); } if (waypoints != null) { StringBuilder waypointsString = new StringBuilder(); for (int i = 0; i < waypoints.size(); i++) { LPWaypoint waypoint = waypoints.get(i); waypointsString .append(String.format("%s,%s|", coordinateDecimalFormat.format(waypoint.location.latitude), coordinateDecimalFormat.format(waypoint.location.longitude))); } parameters.put("waypoints", waypointsString.toString()); } this.client.get(googleAPIDirectionsURL, parameters, new AsyncHttpResponseHandler() { @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { if (responseHandler != null) responseHandler.errorLoadingDirections(LPGoogleStatus.LPGoogleStatusUnknownError); } @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { try { String response = new String(arg2, "UTF-8"); JSONObject object = new JSONObject(response); LPDirections directions = new LPDirections(object); directions.requestTravelMode = travelMode; LPGoogleStatus status = LPGoogleFunctions.getGoogleStatusFromString(directions.statusCode); if (status == LPGoogleStatus.LPGoogleStatusOK) { if (responseHandler != null) responseHandler.didLoadDirections(directions); } else { if (responseHandler != null) responseHandler.errorLoadingDirections(status); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); if (responseHandler != null) responseHandler.errorLoadingDirections(LPGoogleStatus.LPGoogleStatusUnknownError); } catch (JSONException e) { e.printStackTrace(); if (responseHandler != null) responseHandler.errorLoadingDirections(LPGoogleStatus.LPGoogleStatusUnknownError); } } }); }
From source file:org.geomajas.layer.wms.WmsLayer.java
/** * Build the base part of the url (doesn't change for getMap or getFeatureInfo requests). * /*from w w w . ja v a 2 s . c om*/ * @param targetUrl * base url * @param width * image width * @param height * image height * @param box * bounding box * @return base WMS url * @throws GeomajasException * missing parameter */ private StringBuilder formatBaseUrl(String targetUrl, int width, int height, Bbox box) throws GeomajasException { try { StringBuilder url = new StringBuilder(targetUrl); int pos = url.lastIndexOf("?"); if (pos > 0) { url.append("&SERVICE=WMS"); } else { url.append("?SERVICE=WMS"); } String layers = getId(); if (layerInfo.getDataSourceName() != null) { layers = layerInfo.getDataSourceName(); } url.append("&layers="); url.append(URLEncoder.encode(layers, "UTF8")); url.append("&WIDTH="); url.append(Integer.toString(width)); url.append("&HEIGHT="); url.append(Integer.toString(height)); DecimalFormat decimalFormat = new DecimalFormat(); // create new as this is not thread safe decimalFormat.setDecimalSeparatorAlwaysShown(false); decimalFormat.setGroupingUsed(false); decimalFormat.setMinimumFractionDigits(0); decimalFormat.setMaximumFractionDigits(100); DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator('.'); decimalFormat.setDecimalFormatSymbols(symbols); url.append("&bbox="); url.append(decimalFormat.format(box.getX())); url.append(","); url.append(decimalFormat.format(box.getY())); url.append(","); url.append(decimalFormat.format(box.getMaxX())); url.append(","); url.append(decimalFormat.format(box.getMaxY())); url.append("&format="); url.append(format); url.append("&version="); url.append(version); if ("1.3.0".equals(version)) { url.append("&crs="); } else { url.append("&srs="); } url.append(URLEncoder.encode(layerInfo.getCrs(), "UTF8")); url.append("&styles="); url.append(styles); if (null != parameters) { for (Parameter p : parameters) { url.append("&"); url.append(URLEncoder.encode(p.getName(), "UTF8")); url.append("="); url.append(URLEncoder.encode(p.getValue(), "UTF8")); } } if (useProxy && null != securityContext.getToken()) { url.append("&userToken="); url.append(securityContext.getToken()); } return url; } catch (UnsupportedEncodingException uee) { throw new IllegalStateException("Cannot find UTF8 encoding?", uee); } }
From source file:org.orcid.frontend.web.controllers.FundingsController.java
/** * Transforms a string into a BigDecimal * /*from ww w . j av a2 s . co m*/ * @param amount * @param locale * @return a BigDecimal containing the given amount * @throws Exception * if the amount cannot be correctly parse into a BigDecimal * */ public BigDecimal getAmountAsBigDecimal(String amount, Locale locale) throws Exception { try { ParsePosition parsePosition = new ParsePosition(0); DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getNumberInstance(locale); DecimalFormatSymbols symbols = numberFormat.getDecimalFormatSymbols(); /** * When spaces are allowed, the grouping separator is the character * 160, which is a non-breaking space So, lets change it so it uses * the default space as a separator * */ if (symbols.getGroupingSeparator() == 160) { symbols.setGroupingSeparator(' '); } numberFormat.setDecimalFormatSymbols(symbols); Number number = numberFormat.parse(amount, parsePosition); if (number == null || parsePosition.getIndex() != amount.length()) { throw new Exception(); } return new BigDecimal(number.toString()); } catch (Exception e) { throw e; } }
From source file:com.flexive.shared.FxContext.java
/** * Get a number format instance depending on the current users formatting options * * @param locale locale to use//from w w w. ja va2s .c o m * @return NumberFormat */ public NumberFormat getNumberFormatInstance(Locale locale) { final String currentUserKey = buildCurrentUserNumberFormatKey(); if (NUMBER_FORMATS.containsKey(locale)) { Map<String, NumberFormat> map = NUMBER_FORMATS.get(locale); if (map.containsKey(currentUserKey)) return map.get(currentUserKey); } else NUMBER_FORMATS.put(locale, new HashMap<String, NumberFormat>(5)); Map<String, NumberFormat> map = NUMBER_FORMATS.get(locale); DecimalFormat format = (DecimalFormat) DecimalFormat.getNumberInstance(locale); DecimalFormatSymbols dfs = (DecimalFormatSymbols) format.getDecimalFormatSymbols().clone(); dfs.setDecimalSeparator(getDecimalSeparator()); dfs.setGroupingSeparator(getGroupingSeparator()); format.setGroupingUsed(useGroupingSeparator()); format.setDecimalFormatSymbols(dfs); map.put(currentUserKey, format); return format; }
From source file:Matrix.java
/** * Print the matrix to the output stream. Line the elements up in columns * with a Fortran-like 'Fw.d' style format. * /*from w ww. j av a 2s .c o m*/ * @param output * Output stream. * @param w * Column width. * @param d * Number of digits after the decimal. */ public void print(PrintWriter output, int w, int d) { DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(d); format.setMinimumFractionDigits(d); format.setGroupingUsed(false); print(output, format, w + 2); }
From source file:fr.cls.atoll.motu.library.misc.netcdf.NetCdfReader.java
/** * Gets the standard z as string.//from w ww. j a v a 2 s.c o m * * @param value the value * @param roundingMode the rounding mode * @param desiredDecimalNumberDigits the desired decimal number of digits * * @return the standard z as fmt string */ public static String getStandardZAsString(double value, RoundingMode roundingMode, int desiredDecimalNumberDigits) { int in = (int) (value); double frac = value - in; if (frac == 0d) { return NetCdfReader.getStandardZAsString(value); } DecimalFormat decimalFormat = new DecimalFormat(); decimalFormat.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); decimalFormat.setGroupingUsed(false); decimalFormat.setMinimumFractionDigits(desiredDecimalNumberDigits); decimalFormat.setMaximumFractionDigits(desiredDecimalNumberDigits); decimalFormat.setRoundingMode(roundingMode); return decimalFormat.format(value); }
From source file:org.openbravo.erpCommon.utility.Utility.java
/** * Gets the number format for the organization country. * /*from w w w . j a va 2s.c o m*/ * @param orgid * ID of the organization. * @param defaultDecimalFormat * Default decimal format. * * @return DecimalFormat for the number representation defined for the country. */ public static DecimalFormat getCountryNumberFormat(String orgid, DecimalFormat defaultDecimalFormat) { try { OBContext.setAdminMode(true); Country country = getCountryFromOrgId(orgid); DecimalFormatSymbols symbols = new DecimalFormatSymbols(); if (country.getDecimalseparator() != null) symbols.setDecimalSeparator(country.getDecimalseparator().equals("C") ? ',' : '.'); if (country.getGroupingseparator() != null) symbols.setGroupingSeparator(country.getGroupingseparator().equals("C") ? ',' : '.'); if (country.getNumericmask() != null) { DecimalFormat numberFormat = new DecimalFormat(country.getNumericmask()); numberFormat.setDecimalFormatSymbols(symbols); return numberFormat; } else { if (country.getDecimalseparator() != null || country.getNumericmask() != null) { defaultDecimalFormat.setDecimalFormatSymbols(symbols); } return defaultDecimalFormat; } } finally { OBContext.restorePreviousMode(); } }