List of usage examples for java.text DecimalFormat setMaximumFractionDigits
@Override public void setMaximumFractionDigits(int newValue)
From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java
public static void analyseWaitTimes(String fileName, List<DynModeTrip> trips, int binsize_s) { Collections.sort(trips);// w w w . j a va2 s. co m if (trips.size() == 0) return; int startTime = ((int) (trips.get(0).getDepartureTime() / binsize_s)) * binsize_s; int endTime = ((int) (trips.get(trips.size() - 1).getDepartureTime() / binsize_s) + binsize_s) * binsize_s; Map<Double, List<DynModeTrip>> splitTrips = splitTripsIntoBins(trips, startTime, endTime, binsize_s); DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(2); format.setGroupingUsed(false); SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss"); BufferedWriter bw = IOUtils.getBufferedWriter(fileName + ".csv"); TimeSeriesCollection dataset = new TimeSeriesCollection(); TimeSeriesCollection datasetrequ = new TimeSeriesCollection(); TimeSeries averageWaitC = new TimeSeries("average"); TimeSeries medianWait = new TimeSeries("median"); TimeSeries p_5Wait = new TimeSeries("5th percentile"); TimeSeries p_95Wait = new TimeSeries("95th percentile"); TimeSeries requests = new TimeSeries("Ride requests"); try { bw.write("timebin;trips;average_wait;min;p_5;p_25;median;p_75;p_95;max"); for (Entry<Double, List<DynModeTrip>> e : splitTrips.entrySet()) { long rides = 0; double averageWait = 0; double min = 0; double p_5 = 0; double p_25 = 0; double median = 0; double p_75 = 0; double p_95 = 0; double max = 0; if (!e.getValue().isEmpty()) { DescriptiveStatistics stats = new DescriptiveStatistics(); for (DynModeTrip t : e.getValue()) { stats.addValue(t.getWaitTime()); } rides = stats.getN(); averageWait = stats.getMean(); min = stats.getMin(); p_5 = stats.getPercentile(5); p_25 = stats.getPercentile(25); median = stats.getPercentile(50); p_75 = stats.getPercentile(75); p_95 = stats.getPercentile(95); max = stats.getMax(); } Minute h = new Minute(sdf2.parse(Time.writeTime(e.getKey()))); medianWait.addOrUpdate(h, Double.valueOf(median)); averageWaitC.addOrUpdate(h, Double.valueOf(averageWait)); p_5Wait.addOrUpdate(h, Double.valueOf(p_5)); p_95Wait.addOrUpdate(h, Double.valueOf(p_95)); requests.addOrUpdate(h, rides * 3600. / binsize_s);// normalised [req/h] bw.newLine(); bw.write(Time.writeTime(e.getKey()) + ";" + rides + ";" + format.format(averageWait) + ";" + format.format(min) + ";" + format.format(p_5) + ";" + format.format(p_25) + ";" + format.format(median) + ";" + format.format(p_75) + ";" + format.format(p_95) + ";" + format.format(max)); } bw.flush(); bw.close(); dataset.addSeries(averageWaitC); dataset.addSeries(medianWait); dataset.addSeries(p_5Wait); dataset.addSeries(p_95Wait); datasetrequ.addSeries(requests); JFreeChart chart = chartProfile(splitTrips.size(), dataset, "Waiting times", "Wait time (s)"); JFreeChart chart2 = chartProfile(splitTrips.size(), datasetrequ, "Ride requests per hour", "Requests per hour (req/h)"); ChartSaveUtils.saveAsPNG(chart, fileName, 1500, 1000); ChartSaveUtils.saveAsPNG(chart2, fileName + "_requests", 1500, 1000); } catch (IOException | ParseException e) { e.printStackTrace(); } }
From source file:com.itude.mobile.mobbl.core.util.StringUtilities.java
public static String formatVolume(String stringToFormat) { if (stringToFormat == null || stringToFormat.length() == 0) { return null; }//from ww w .ja va2 s . co m String result = null; DecimalFormat formatter = new DecimalFormat(); formatter.setDecimalFormatSymbols(new DecimalFormatSymbols(getDefaultFormattingLocale())); formatter.setGroupingUsed(true); formatter.setGroupingSize(3); formatter.setMaximumFractionDigits(0); result = formatter.format(Double.parseDouble(stringToFormat)); return result; }
From source file:org.mitre.ccv.mapred.CalculateCosineDistanceMatrix.java
/** * Writes out the matrix in row major (packed) order. No labels are outputed. * * @param jobConf// ww w . j a v a 2 s. co m * @param input * @param output * @param digits * @throws IOException */ public static void printRowMajorMatrix(JobConf jobConf, String input, String output, int digits) throws IOException { JobConf conf = new JobConf(jobConf, CalculateCosineDistanceMatrix.class); DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(digits); //format.setMinimumFractionDigits(fractionDigits); format.setGroupingUsed(false); final Path inputPath = new Path(input); final FileSystem fs = inputPath.getFileSystem(conf); final Path qInputPath = fs.makeQualified(inputPath); final Path outputPath = new Path(output); Path[] paths = FileUtils.ls(conf, qInputPath.toString() + Path.SEPARATOR + "part-*"); FSDataOutputStream fos = fs.create(outputPath, true); // throws nothing! final Writer writer = new OutputStreamWriter(fos); final Text key = new Text(); final DenseVectorWritable value = new DenseVectorWritable(); for (int idx = 0; idx < paths.length; idx++) { SequenceFile.Reader reader = new SequenceFile.Reader(fs, paths[idx], conf); boolean hasNext = reader.next(key, value); while (hasNext) { final DenseVector vector = value.get(); final StringBuilder sb = new StringBuilder(); for (int i = 0; i < vector.getCardinality(); i++) { final String s = format.format(vector.get(i)); // format the number sb.append(s); sb.append(' '); } writer.write(sb.toString()); hasNext = reader.next(key, value); } try { writer.flush(); reader.close(); } catch (IOException ioe) { // closing the SequenceFile.Reader will throw an exception if the file is over some unknown size LOG.debug("Probably caused by closing the SequenceFile.Reader. All is well", ioe); } } try { writer.close(); fos.flush(); fos.close(); } catch (IOException ioe) { LOG.debug("Caused by distributed cache output stream.", ioe); } }
From source file:org.mitre.ccv.mapred.CalculateCosineDistanceMatrix.java
/** * Outputs the distance matrix (DenseVectors) in Phylip Square format. Names/labels are limited to 10-characters! * * @param jobConf/*from ww w . j a v a2 s. co m*/ * @param input input directory name containing DenseVectors (as generated by this class). * @param output output file name * @param fractionDigits number of digits after decimal point * @throws IOException */ public static void printPhylipSquare(JobConf jobConf, String input, String output, int fractionDigits) throws IOException { JobConf conf = new JobConf(jobConf, CalculateCosineDistanceMatrix.class); DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(fractionDigits); //format.setMinimumFractionDigits(fractionDigits); format.setGroupingUsed(false); final Path inputPath = new Path(input); final FileSystem fs = inputPath.getFileSystem(conf); final Path qInputPath = fs.makeQualified(inputPath); final Path outputPath = new Path(output); Path[] paths = FileUtils.ls(conf, qInputPath.toString() + Path.SEPARATOR + "part-*"); FSDataOutputStream fos = fs.create(outputPath, true); // throws nothing! Writer writer = new OutputStreamWriter(fos); Text key = new Text(); DenseVectorWritable value = new DenseVectorWritable(); Boolean wroteHeader = false; for (int idx = 0; idx < paths.length; idx++) { SequenceFile.Reader reader = new SequenceFile.Reader(fs, paths[idx], conf); boolean hasNext = reader.next(key, value); while (hasNext) { final DenseVector vector = value.get(); if (!wroteHeader) { writer.write(String.format("\t%d\n", vector.getCardinality())); wroteHeader = true; } final StringBuilder sb = new StringBuilder(); final String name = key.toString(); sb.append(name.substring(0, (name.length() > 10 ? 10 : name.length()))); final int padding = Math.max(1, 10 - name.length()); for (int k = 0; k < padding; k++) { sb.append(' '); } sb.append(' '); for (int i = 0; i < vector.getCardinality(); i++) { final String s = format.format(vector.get(i)); // format the number sb.append(s); sb.append(' '); } sb.append("\n"); writer.write(sb.toString()); hasNext = reader.next(key, value); } try { writer.flush(); reader.close(); } catch (IOException ioe) { // closing the SequenceFile.Reader will throw an exception if the file is over some unknown size LOG.debug("Probably caused by closing the SequenceFile.Reader. All is well", ioe); } } try { writer.close(); fos.flush(); fos.close(); } catch (IOException ioe) { LOG.debug("Caused by distributed cache output stream.", ioe); } }
From source file:com.coinblesk.client.utils.UIUtils.java
public static String coinToAmount(Context context, Coin coin) { // transform a given coin value to the "amount string". BigDecimal coinAmount = new BigDecimal(coin.getValue()); BigDecimal div = new BigDecimal(Coin.COIN.getValue()); if (SharedPrefUtils.isBitcoinScaleBTC(context)) { div = new BigDecimal(Coin.COIN.getValue()); } else if (SharedPrefUtils.isBitcoinScaleMilliBTC(context)) { div = new BigDecimal(Coin.MILLICOIN.getValue()); } else if (SharedPrefUtils.isBitcoinScaleMicroBTC(context)) { div = new BigDecimal(Coin.MICROCOIN.getValue()); }/*w w w . j a v a 2 s. c om*/ DecimalFormat df = new DecimalFormat("#.####"); df.setRoundingMode(RoundingMode.DOWN); df.setMaximumFractionDigits(4); DecimalFormatSymbols decFormat = new DecimalFormatSymbols(); decFormat.setDecimalSeparator('.'); df.setDecimalFormatSymbols(decFormat); String amount = df.format(coinAmount.divide(div)); return amount; }
From source file:org.onebusaway.nyc.presentation.impl.realtime.SiriSupport.java
/** * NOTE: The tripDetails bean here may not be for the trip the vehicle is currently on * in the case of A-D for stop!/*from ww w. j ava 2s .com*/ */ public static void fillMonitoredVehicleJourney(MonitoredVehicleJourneyStructure monitoredVehicleJourney, TripBean framedJourneyTripBean, TripStatusBean currentVehicleTripStatus, StopBean monitoredCallStopBean, OnwardCallsMode onwardCallsMode, PresentationService presentationService, NycTransitDataService nycTransitDataService, int maximumOnwardCalls, List<TimepointPredictionRecord> stopLevelPredictions, long responseTimestamp) { BlockInstanceBean blockInstance = nycTransitDataService.getBlockInstance( currentVehicleTripStatus.getActiveTrip().getBlockId(), currentVehicleTripStatus.getServiceDate()); List<BlockTripBean> blockTrips = blockInstance.getBlockConfiguration().getTrips(); if (monitoredCallStopBean == null) { monitoredCallStopBean = currentVehicleTripStatus.getNextStop(); } ///////////// LineRefStructure lineRef = new LineRefStructure(); lineRef.setValue(framedJourneyTripBean.getRoute().getId()); monitoredVehicleJourney.setLineRef(lineRef); OperatorRefStructure operatorRef = new OperatorRefStructure(); operatorRef.setValue(AgencySupportLibrary.getAgencyForId(framedJourneyTripBean.getRoute().getId())); monitoredVehicleJourney.setOperatorRef(operatorRef); DirectionRefStructure directionRef = new DirectionRefStructure(); directionRef.setValue(framedJourneyTripBean.getDirectionId()); monitoredVehicleJourney.setDirectionRef(directionRef); NaturalLanguageStringStructure routeShortName = new NaturalLanguageStringStructure(); routeShortName.setValue(framedJourneyTripBean.getRoute().getShortName()); monitoredVehicleJourney.setPublishedLineName(routeShortName); JourneyPatternRefStructure journeyPattern = new JourneyPatternRefStructure(); journeyPattern.setValue(framedJourneyTripBean.getShapeId()); monitoredVehicleJourney.setJourneyPatternRef(journeyPattern); NaturalLanguageStringStructure headsign = new NaturalLanguageStringStructure(); headsign.setValue(framedJourneyTripBean.getTripHeadsign()); monitoredVehicleJourney.setDestinationName(headsign); VehicleRefStructure vehicleRef = new VehicleRefStructure(); vehicleRef.setValue(currentVehicleTripStatus.getVehicleId()); monitoredVehicleJourney.setVehicleRef(vehicleRef); monitoredVehicleJourney.setMonitored(currentVehicleTripStatus.isPredicted()); monitoredVehicleJourney.setBearing((float) currentVehicleTripStatus.getOrientation()); monitoredVehicleJourney.setProgressRate(getProgressRateForPhaseAndStatus( currentVehicleTripStatus.getStatus(), currentVehicleTripStatus.getPhase())); // origin-destination for (int i = 0; i < blockTrips.size(); i++) { BlockTripBean blockTrip = blockTrips.get(i); if (blockTrip.getTrip().getId().equals(framedJourneyTripBean.getId())) { List<BlockStopTimeBean> stops = blockTrip.getBlockStopTimes(); JourneyPlaceRefStructure origin = new JourneyPlaceRefStructure(); origin.setValue(stops.get(0).getStopTime().getStop().getId()); monitoredVehicleJourney.setOriginRef(origin); StopBean lastStop = stops.get(stops.size() - 1).getStopTime().getStop(); DestinationRefStructure dest = new DestinationRefStructure(); dest.setValue(lastStop.getId()); monitoredVehicleJourney.setDestinationRef(dest); break; } } // framed journey FramedVehicleJourneyRefStructure framedJourney = new FramedVehicleJourneyRefStructure(); DataFrameRefStructure dataFrame = new DataFrameRefStructure(); dataFrame.setValue(String.format("%1$tY-%1$tm-%1$td", currentVehicleTripStatus.getServiceDate())); framedJourney.setDataFrameRef(dataFrame); framedJourney.setDatedVehicleJourneyRef(framedJourneyTripBean.getId()); monitoredVehicleJourney.setFramedVehicleJourneyRef(framedJourney); // location // if vehicle is detected to be on detour, use actual lat/lon, not snapped location. LocationStructure location = new LocationStructure(); DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(6); if (presentationService.isOnDetour(currentVehicleTripStatus)) { location.setLatitude( new BigDecimal(df.format(currentVehicleTripStatus.getLastKnownLocation().getLat()))); location.setLongitude( new BigDecimal(df.format(currentVehicleTripStatus.getLastKnownLocation().getLon()))); } else { location.setLatitude(new BigDecimal(df.format(currentVehicleTripStatus.getLocation().getLat()))); location.setLongitude(new BigDecimal(df.format(currentVehicleTripStatus.getLocation().getLon()))); } monitoredVehicleJourney.setVehicleLocation(location); // progress status List<String> progressStatuses = new ArrayList<String>(); if (presentationService.isInLayover(currentVehicleTripStatus)) { progressStatuses.add("layover"); } // "prevTrip" really means not on the framedvehiclejourney trip if (!framedJourneyTripBean.getId().equals(currentVehicleTripStatus.getActiveTrip().getId())) { progressStatuses.add("prevTrip"); } if (!progressStatuses.isEmpty()) { NaturalLanguageStringStructure progressStatus = new NaturalLanguageStringStructure(); progressStatus.setValue(StringUtils.join(progressStatuses, ",")); monitoredVehicleJourney.setProgressStatus(progressStatus); } // block ref if (presentationService.isBlockLevelInference(currentVehicleTripStatus)) { BlockRefStructure blockRef = new BlockRefStructure(); blockRef.setValue(framedJourneyTripBean.getBlockId()); monitoredVehicleJourney.setBlockRef(blockRef); } // scheduled depature time if (presentationService.isBlockLevelInference(currentVehicleTripStatus) && (presentationService .isInLayover(currentVehicleTripStatus) || !framedJourneyTripBean.getId().equals(currentVehicleTripStatus.getActiveTrip().getId()))) { BlockStopTimeBean originDepartureStopTime = null; for (int t = 0; t < blockTrips.size(); t++) { BlockTripBean thisTrip = blockTrips.get(t); BlockTripBean nextTrip = null; if (t + 1 < blockTrips.size()) { nextTrip = blockTrips.get(t + 1); } if (thisTrip.getTrip().getId().equals(currentVehicleTripStatus.getActiveTrip().getId())) { // just started new trip if (currentVehicleTripStatus.getDistanceAlongTrip() < (0.5 * currentVehicleTripStatus.getTotalDistanceAlongTrip())) { originDepartureStopTime = thisTrip.getBlockStopTimes().get(0); // at end of previous trip } else { if (nextTrip != null) { originDepartureStopTime = nextTrip.getBlockStopTimes().get(0); } } break; } } if (originDepartureStopTime != null) { Date departureTime = new Date(currentVehicleTripStatus.getServiceDate() + (originDepartureStopTime.getStopTime().getDepartureTime() * 1000)); monitoredVehicleJourney.setOriginAimedDepartureTime(departureTime); } } Map<String, TimepointPredictionRecord> stopIdToPredictionRecordMap = new HashMap<String, TimepointPredictionRecord>(); // (build map of stop IDs to TPRs) if (stopLevelPredictions != null) { for (TimepointPredictionRecord tpr : stopLevelPredictions) { stopIdToPredictionRecordMap.put(AgencyAndId.convertToString(tpr.getTimepointId()), tpr); } } // monitored call if (!presentationService.isOnDetour(currentVehicleTripStatus)) fillMonitoredCall(monitoredVehicleJourney, blockInstance, currentVehicleTripStatus, monitoredCallStopBean, presentationService, nycTransitDataService, stopIdToPredictionRecordMap, responseTimestamp); // onward calls if (!presentationService.isOnDetour(currentVehicleTripStatus)) fillOnwardCalls(monitoredVehicleJourney, blockInstance, framedJourneyTripBean, currentVehicleTripStatus, onwardCallsMode, presentationService, nycTransitDataService, stopIdToPredictionRecordMap, maximumOnwardCalls, responseTimestamp); // situations fillSituations(monitoredVehicleJourney, currentVehicleTripStatus); return; }
From source file:org.onebusaway.presentation.impl.realtime.SiriSupport.java
private static OnwardCallStructure getOnwardCallStructure(StopBean stopBean, PresentationService presentationService, double distanceOfCallAlongTrip, double distanceOfVehicleFromCall, int visitNumber, int index, TimepointPredictionRecord prediction, boolean hasRealtimeData, long responseTimestamp, long scheduledArrivalTime) { OnwardCallStructure onwardCallStructure = new OnwardCallStructure(); onwardCallStructure.setVisitNumber(BigInteger.valueOf(visitNumber)); StopPointRefStructure stopPointRef = new StopPointRefStructure(); stopPointRef.setValue(stopBean.getId()); onwardCallStructure.setStopPointRef(stopPointRef); if (stopBean.getCode() != null) { // Agency's prefer stop code display in UI, so override platform name for this use NaturalLanguageStringStructure platform = new NaturalLanguageStringStructure(); platform.setValue(stopBean.getCode()); onwardCallStructure.setArrivalPlatformName(platform); }/* www .ja va 2 s.c o m*/ NaturalLanguageStringStructure stopPoint = new NaturalLanguageStringStructure(); stopPoint.setValue(stopBean.getName()); onwardCallStructure.setStopPointName(stopPoint); if (prediction != null) { if (prediction.getTimepointPredictedArrivalTime() < responseTimestamp) { onwardCallStructure.setExpectedArrivalTime(new Date(responseTimestamp)); onwardCallStructure.setExpectedDepartureTime(new Date(responseTimestamp)); } else { onwardCallStructure.setExpectedArrivalTime(new Date(prediction.getTimepointPredictedArrivalTime())); onwardCallStructure .setExpectedDepartureTime(new Date(prediction.getTimepointPredictedDepartureTime())); } } else if (!hasRealtimeData) { _log.debug("using arrival time of " + new Date(scheduledArrivalTime)); onwardCallStructure.setExpectedArrivalTime(new Date(scheduledArrivalTime)); onwardCallStructure.setExpectedDepartureTime(new Date(scheduledArrivalTime)); } // siri extensions SiriExtensionWrapper wrapper = new SiriExtensionWrapper(); ExtensionsStructure distancesExtensions = new ExtensionsStructure(); SiriDistanceExtension distances = new SiriDistanceExtension(); DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2); df.setGroupingUsed(false); distances.setStopsFromCall(index); distances.setCallDistanceAlongRoute(NumberUtils.toDouble(df.format(distanceOfCallAlongTrip))); distances.setDistanceFromCall(NumberUtils.toDouble(df.format(distanceOfVehicleFromCall))); distances.setPresentableDistance(presentationService.getPresentableDistance(distances)); wrapper.setDistances(distances); distancesExtensions.setAny(wrapper); onwardCallStructure.setExtensions(distancesExtensions); return onwardCallStructure; }
From source file:org.onebusaway.presentation.impl.realtime.SiriSupport.java
private static MonitoredCallStructure getMonitoredCallStructure(StopBean stopBean, PresentationService presentationService, double distanceOfCallAlongTrip, double distanceOfVehicleFromCall, int visitNumber, int index, TimepointPredictionRecord prediction, boolean hasRealtimeData, long responseTimestamp, long scheduledArrivalTime) { MonitoredCallStructure monitoredCallStructure = new MonitoredCallStructure(); monitoredCallStructure.setVisitNumber(BigInteger.valueOf(visitNumber)); StopPointRefStructure stopPointRef = new StopPointRefStructure(); stopPointRef.setValue(stopBean.getId()); monitoredCallStructure.setStopPointRef(stopPointRef); NaturalLanguageStringStructure stopPoint = new NaturalLanguageStringStructure(); stopPoint.setValue(stopBean.getName()); monitoredCallStructure.setStopPointName(stopPoint); if (prediction != null) { if (!hasRealtimeData) { monitoredCallStructure.setExpectedArrivalTime(new Date(prediction.getTimepointScheduledTime())); monitoredCallStructure.setExpectedDepartureTime(new Date(prediction.getTimepointScheduledTime())); }/*from w ww .j a va 2 s.co m*/ // do not allow predicted times to be less than ResponseTimestamp else if (prediction.getTimepointPredictedArrivalTime() < responseTimestamp) { /* * monitoredCall has less precision than onwardCall (date vs. timestamp) * which results in a small amount of error when converting back to timestamp. * Add a second here to prevent negative values from showing up in the UI * (actual precision of the value is 1 minute, so a second has little influence) */ monitoredCallStructure.setExpectedArrivalTime(new Date(responseTimestamp + 1000)); monitoredCallStructure.setExpectedDepartureTime(new Date(responseTimestamp + 1000)); } else { monitoredCallStructure .setExpectedArrivalTime(new Date(prediction.getTimepointPredictedArrivalTime())); monitoredCallStructure .setExpectedDepartureTime(new Date(prediction.getTimepointPredictedArrivalTime())); } } else if (!hasRealtimeData) { monitoredCallStructure.setExpectedArrivalTime(new Date(scheduledArrivalTime)); monitoredCallStructure.setExpectedDepartureTime(new Date(scheduledArrivalTime)); } //setting the scheduled arrival time. if (monitoredCallStructure.getExpectedArrivalTime() != null) { monitoredCallStructure.setAimedArrivalTime(new Date(scheduledArrivalTime)); } // siri extensions SiriExtensionWrapper wrapper = new SiriExtensionWrapper(); ExtensionsStructure distancesExtensions = new ExtensionsStructure(); SiriDistanceExtension distances = new SiriDistanceExtension(); DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2); df.setGroupingUsed(false); distances.setStopsFromCall(index); distances.setCallDistanceAlongRoute(NumberUtils.toDouble(df.format(distanceOfCallAlongTrip))); distances.setDistanceFromCall(NumberUtils.toDouble(df.format(distanceOfVehicleFromCall))); distances.setPresentableDistance(presentationService.getPresentableDistance(distances)); wrapper.setDistances(distances); distancesExtensions.setAny(wrapper); monitoredCallStructure.setExtensions(distancesExtensions); return monitoredCallStructure; }
From source file:com.itude.mobile.mobbl.core.util.StringUtilities.java
private static void setupFormatter(DecimalFormat formatter, int minumumDecimals, int maximumDecimals) { formatter.setDecimalFormatSymbols(new DecimalFormatSymbols(getDefaultFormattingLocale())); formatter.setMinimumIntegerDigits(1); if (minumumDecimals > -1) { formatter.setMinimumFractionDigits(minumumDecimals); }/*from ww w. ja va 2s. com*/ if (maximumDecimals > -1) { formatter.setMaximumFractionDigits(maximumDecimals); } formatter.setGroupingUsed(true); formatter.setGroupingSize(3); }
From source file:com.itude.mobile.android.util.StringUtil.java
/** * Format {@link String} as a Volume//from w w w . j av a 2 s . c om * * WARNING: Only use this method to present data to the screen * * @param locale {@link Locale} * @param stringToFormat {@link String} to format * @return a string formatted as a volume with group separators (eg, 131.224.000) assuming the receiver is an int string read from XML */ public static String formatVolume(Locale locale, String stringToFormat) { if (stringToFormat == null || stringToFormat.length() == 0) { return null; } String result = null; DecimalFormat formatter = new DecimalFormat(); formatter.setDecimalFormatSymbols(new DecimalFormatSymbols(locale)); formatter.setGroupingUsed(true); formatter.setGroupingSize(3); formatter.setMaximumFractionDigits(0); result = formatter.format(Double.parseDouble(stringToFormat)); return result; }