List of usage examples for java.text DecimalFormat setMaximumFractionDigits
@Override public void setMaximumFractionDigits(int newValue)
From source file:com.jaspersoft.jasperserver.war.cascade.handlers.converters.DoubleDataConverter.java
@Override public String valueToString(Double value) { if (value == null) return ""; DecimalFormat df = (DecimalFormat) NumberFormat.getNumberInstance(LocaleContextHolder.getLocale()); df.setGroupingUsed(false);/*from ww w.ja v a 2 s.c om*/ df.setMaximumFractionDigits(Integer.MAX_VALUE); return df.format(value); }
From source file:com.jaspersoft.jasperserver.war.cascade.handlers.converters.FloatDataConverter.java
@Override public String valueToString(Float value) { if (value == null) return ""; DecimalFormat df = (DecimalFormat) NumberFormat.getNumberInstance(LocaleContextHolder.getLocale()); df.setGroupingUsed(false);/*from ww w. j a va2 s .com*/ df.setMaximumFractionDigits(Integer.MAX_VALUE); return df.format(value); }
From source file:com.mifos.mifosxdroid.adapters.SavingsAccountsListAdapter.java
@SuppressWarnings("deprecation") @Override/*from w ww .jav a2s. c om*/ public View getView(int i, View view, ViewGroup viewGroup) { ReusableViewHolder reusableViewHolder; if (view == null) { view = layoutInflater.inflate(R.layout.row_account_item, null); reusableViewHolder = new ReusableViewHolder(view); view.setTag(reusableViewHolder); } else { reusableViewHolder = (ReusableViewHolder) view.getTag(); } if (savingsAccountList.get(i).getStatus().getActive()) { reusableViewHolder.view_status_indicator .setBackgroundColor(ContextCompat.getColor(context, R.color.savings_account_status_active)); } else if (savingsAccountList.get(i).getStatus().getApproved()) { reusableViewHolder.view_status_indicator .setBackgroundColor(ContextCompat.getColor(context, R.color.status_approved)); } else if (savingsAccountList.get(i).getStatus().getSubmittedAndPendingApproval()) { reusableViewHolder.view_status_indicator.setBackgroundColor( ContextCompat.getColor(context, R.color.status_submitted_and_pending_approval)); } else { reusableViewHolder.view_status_indicator .setBackgroundColor(ContextCompat.getColor(context, R.color.status_closed)); } Double accountBalance = savingsAccountList.get(i).getAccountBalance(); DecimalFormat decimalFormat = new DecimalFormat("#.##"); decimalFormat.setMaximumFractionDigits(2); decimalFormat.setMaximumIntegerDigits(10); reusableViewHolder.tv_amount .setText(String.valueOf(accountBalance == null ? "0.00" : decimalFormat.format(accountBalance))); reusableViewHolder.tv_accountNumber.setText(savingsAccountList.get(i).getAccountNo()); return view; }
From source file:piazza.services.ingest.util.GeoJsonSerializer.java
private void writePointCoords(JsonGenerator jgen, Point p) throws IOException { jgen.writeStartArray();/*w ww . j a va 2s. c o m*/ DecimalFormat df = new DecimalFormat("#.#"); df.setMaximumFractionDigits(8); jgen.writeNumber(df.format(p.getX())); jgen.writeNumber(df.format(p.getY())); jgen.writeEndArray(); }
From source file:org.onebusaway.api.actions.siri.impl.SiriSupportV2.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! * @param filters // w ww. ja v a 2 s.c o m */ public static void fillMonitoredVehicleJourney(MonitoredVehicleJourneyStructure monitoredVehicleJourney, TripBean framedJourneyTripBean, TripStatusBean currentVehicleTripStatus, StopBean monitoredCallStopBean, OnwardCallsMode onwardCallsMode, PresentationService presentationService, TransitDataService transitDataService, int maximumOnwardCalls, List<TimepointPredictionRecord> stopLevelPredictions, boolean hasRealtimeData, DetailLevel detailLevel, long responseTimestamp, Map<Filters, String> filters) { BlockInstanceBean blockInstance = transitDataService.getBlockInstance( currentVehicleTripStatus.getActiveTrip().getBlockId(), currentVehicleTripStatus.getServiceDate()); List<BlockTripBean> blockTrips = blockInstance.getBlockConfiguration().getTrips(); if (monitoredCallStopBean == null) { monitoredCallStopBean = currentVehicleTripStatus.getNextStop(); } /**********************************************/ //Route ID LineRefStructure lineRef = new LineRefStructure(); lineRef.setValue(framedJourneyTripBean.getRoute().getId()); DirectionRefStructure directionRef = new DirectionRefStructure(); directionRef.setValue(framedJourneyTripBean.getDirectionId()); //Route Short Name NaturalLanguageStringStructure routeShortName = new NaturalLanguageStringStructure(); String shortName = framedJourneyTripBean.getRoute().getShortName(); if (!isBlank(currentVehicleTripStatus.getActiveTrip().getRouteShortName())) { // look for an override like an express desginator shortName = currentVehicleTripStatus.getActiveTrip().getRouteShortName(); } if (shortName == null) { shortName = framedJourneyTripBean.getRoute().getId().split("_")[1]; } routeShortName.setValue(shortName); //Agency Id OperatorRefStructure operatorRef = new OperatorRefStructure(); operatorRef.setValue(AgencySupportLibrary.getAgencyForId(framedJourneyTripBean.getRoute().getId())); //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()); //Shape Id JourneyPatternRefStructure journeyPattern = new JourneyPatternRefStructure(); journeyPattern.setValue(framedJourneyTripBean.getShapeId()); //Destination NaturalLanguageStringStructure headsign = new NaturalLanguageStringStructure(); headsign.setValue(framedJourneyTripBean.getTripHeadsign()); // Vehicle Id VehicleRefStructure vehicleRef = new VehicleRefStructure(); if (currentVehicleTripStatus.getVehicleId() == null) { String tripId = framedJourneyTripBean.getId(); String blockId = framedJourneyTripBean.getBlockId(); String directionId = framedJourneyTripBean.getDirectionId(); String vehicleIdHash = Integer.toString((tripId + blockId + directionId).hashCode()); String agencyName = tripId.split("_")[0]; String vehicleId = agencyName + "_" + vehicleIdHash; vehicleRef.setValue(vehicleId); } else { vehicleRef.setValue(currentVehicleTripStatus.getVehicleId()); } // Set Origin and Destination stops from Block trips. StopBean lastStop = new StopBean(); JourneyPlaceRefStructure origin = new JourneyPlaceRefStructure(); 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(); origin.setValue(stops.get(0).getStopTime().getStop().getId()); lastStop = stops.get(stops.size() - 1).getStopTime().getStop(); break; } } // 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()))); } // 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.getProgressStatus().add(progressStatus); } // 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) { long departureTime = currentVehicleTripStatus.getServiceDate() + (originDepartureStopTime.getStopTime().getDepartureTime() * 1000); monitoredVehicleJourney.setOriginAimedDepartureTime(DateUtil.toXmlGregorianCalendar(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, transitDataService, stopIdToPredictionRecordMap, hasRealtimeData, detailLevel, responseTimestamp); // detail level - minimal if (detailLevel.equals(DetailLevel.MINIMUM) || detailLevel.equals(DetailLevel.BASIC) || detailLevel.equals(DetailLevel.NORMAL) || detailLevel.equals(DetailLevel.CALLS)) { monitoredVehicleJourney.getPublishedLineName().add(routeShortName); monitoredVehicleJourney.getDestinationName().add(headsign); monitoredVehicleJourney.setMonitored(currentVehicleTripStatus.isPredicted()); monitoredVehicleJourney.getVehicleMode().add(toVehicleMode(currentVehicleTripStatus.getVehicleType())); monitoredVehicleJourney.setVehicleRef(vehicleRef); monitoredVehicleJourney.setBearing((float) currentVehicleTripStatus.getOrientation()); monitoredVehicleJourney.setVehicleLocation(location); } // detail level - basic if (detailLevel.equals(DetailLevel.BASIC) || detailLevel.equals(DetailLevel.NORMAL) || detailLevel.equals(DetailLevel.CALLS)) { monitoredVehicleJourney.setFramedVehicleJourneyRef(framedJourney); monitoredVehicleJourney.setDirectionRef(directionRef); // since LineRef is fully qualified with operatorref, moving OperatorRef to normal detail //monitoredVehicleJourney.setOperatorRef(operatorRef); DestinationRefStructure dest = new DestinationRefStructure(); dest.setValue(lastStop.getId()); monitoredVehicleJourney.setDestinationRef(dest); monitoredVehicleJourney.setLineRef(lineRef); monitoredVehicleJourney.setProgressRate(getProgressRateForPhaseAndStatus( currentVehicleTripStatus.getStatus(), currentVehicleTripStatus.getPhase())); } // detail level - normal if (detailLevel.equals(DetailLevel.NORMAL) || detailLevel.equals(DetailLevel.CALLS)) { monitoredVehicleJourney.setOperatorRef(operatorRef); // block ref if (presentationService.isBlockLevelInference(currentVehicleTripStatus)) { BlockRefStructure blockRef = new BlockRefStructure(); blockRef.setValue(framedJourneyTripBean.getBlockId()); monitoredVehicleJourney.setBlockRef(blockRef); } monitoredVehicleJourney.setOriginRef(origin); monitoredVehicleJourney.setJourneyPatternRef(journeyPattern); } // onward calls if (detailLevel.equals(DetailLevel.CALLS)) { if (!presentationService.isOnDetour(currentVehicleTripStatus)) fillOnwardCalls(monitoredVehicleJourney, blockInstance, framedJourneyTripBean, currentVehicleTripStatus, onwardCallsMode, presentationService, transitDataService, stopIdToPredictionRecordMap, maximumOnwardCalls, responseTimestamp); } // situations fillSituations(monitoredVehicleJourney, currentVehicleTripStatus); return; }
From source file:org.arkanos.aos.api.data.Work.java
@Override public String toString() { DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(1); df.setGroupingUsed(false);/*from ww w . j av a 2 s.c om*/ SimpleDateFormat sdf = new SimpleDateFormat(Work.DATEFORMAT); String result = "{\""; try { result += "id\":\"" + this.task_id + "_" + sdf.parse(this.start).getTime() + "\",\""; result += Work.FIELD_TASK_ID + "\":" + this.task_id + ",\""; result += Work.FIELD_START + "\":\"" + this.start.substring(0, this.start.indexOf(".")) + "\",\""; result += Work.FIELD_COMMENT + "\":\"" + JSONObject.escape(this.comment) + "\",\""; result += Work.FIELD_RESULT + "\":" + this.result + ",\""; result += Work.FIELD_TIME_SPENT + "\":" + df.format(this.time_spent / 60.0f) + ",\""; result += Work.EXTRA_TASK_NAME + "\":\"" + this.task_name + "\",\""; result += Work.EXTRA_GOAL_TITLE + "\":\"" + this.goal_title + "\"}"; } catch (ParseException e) { Log.error("Work", "Problems while parsing Work to a JSON."); e.printStackTrace(); return "{\"error\":\"parsing\"}"; } return result; }
From source file:org.biokoframework.system.repository.sql.translator.annotation.impl.DoubleTranslator.java
@Override public String convertFromDBValue(String fieldName, ResultSet resultset, Field fieldAnnotation) throws SQLException { if (StringUtils.isEmpty(fieldAnnotation.format())) { DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getInstance(Locale.ENGLISH); decimalFormat.setDecimalSeparatorAlwaysShown(false); decimalFormat.setMaximumFractionDigits(50); return decimalFormat.format(resultset.getDouble(fieldName)); }/* ww w. ja v a 2 s .com*/ DecimalFormat decimalFormat = new DecimalFormat(fieldAnnotation.format()); // DecimalFormat decimalFormat = new DecimalFormat(); // decimalFormat.setDecimalSeparatorAlwaysShown(false); return decimalFormat.format(resultset.getDouble(fieldName)); }
From source file:com.ancientprogramming.fixedformat4j.format.impl.AbstractDecimalFormatter.java
public String asString(T obj, FormatInstructions instructions) { BigDecimal roundedValue = null; int decimals = instructions.getFixedFormatDecimalData().getDecimals(); if (obj != null) { BigDecimal value = obj instanceof BigDecimal ? (BigDecimal) obj : BigDecimal.valueOf(obj.doubleValue()); RoundingMode roundingMode = instructions.getFixedFormatDecimalData().getRoundingMode(); roundedValue = value.setScale(decimals, roundingMode); if (LOG.isDebugEnabled()) { LOG.debug("Value before rounding = '" + value + "', value after rounding = '" + roundedValue + "', decimals = " + decimals + ", rounding mode = " + roundingMode); }//from w w w.jav a 2 s.c o m } DecimalFormat formatter = new DecimalFormat(); formatter.setDecimalSeparatorAlwaysShown(true); formatter.setMaximumFractionDigits(decimals); char decimalSeparator = formatter.getDecimalFormatSymbols().getDecimalSeparator(); char groupingSeparator = formatter.getDecimalFormatSymbols().getGroupingSeparator(); String zeroString = "0" + decimalSeparator + "0"; String rawString = roundedValue != null ? formatter.format(roundedValue) : zeroString; if (LOG.isDebugEnabled()) { LOG.debug("rawString: " + rawString + " - G[" + groupingSeparator + "] D[" + decimalSeparator + "]"); } rawString = rawString.replaceAll("\\" + groupingSeparator, ""); boolean useDecimalDelimiter = instructions.getFixedFormatDecimalData().isUseDecimalDelimiter(); String beforeDelimiter = rawString.substring(0, rawString.indexOf(decimalSeparator)); String afterDelimiter = rawString.substring(rawString.indexOf(decimalSeparator) + 1, rawString.length()); if (LOG.isDebugEnabled()) { LOG.debug("beforeDelimiter[" + beforeDelimiter + "], afterDelimiter[" + afterDelimiter + "]"); } //trim decimals afterDelimiter = StringUtils.substring(afterDelimiter, 0, decimals); afterDelimiter = StringUtils.rightPad(afterDelimiter, decimals, '0'); String delimiter = useDecimalDelimiter ? "" + instructions.getFixedFormatDecimalData().getDecimalDelimiter() : ""; String result = beforeDelimiter + delimiter + afterDelimiter; if (LOG.isDebugEnabled()) { LOG.debug("result[" + result + "]"); } return result; }
From source file:com.rstar.mobile.thermocouple.ui.NumericKeypadDialogFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Savelog.d(TAG, debug, "onCreate()"); mInputCode = getArguments().getString(EXTRA_code); mData = getArguments().getDouble(EXTRA_data); mHint = getArguments().getString(EXTRA_hint); if (Double.isNaN(mData)) mInput = ""; else {//from w w w . ja v a 2 s.c om DecimalFormat df = new DecimalFormat("#"); df.setMaximumFractionDigits(4); mInput = df.format(mData); } setRetainInstance(true); }
From source file:com.ar.dev.tierra.api.dao.impl.FiscalDAOImpl.java
@Override public void ticket(List<DetalleFactura> detalles) { try (PrintWriter ticket = new PrintWriter("command/ticket.200")) { DecimalFormat decimalFormat = new DecimalFormat(); decimalFormat.setMaximumFractionDigits(1); ticket.println("@" + (char) 28 + "T" + (char) 28 + "T"); BigDecimal descuento = new BigDecimal(BigInteger.ZERO); for (DetalleFactura detalle : detalles) { if (detalle.getDescuentoDetalle() != null) { descuento = descuento.add(detalle.getDescuentoDetalle()); }/*from w w w. j av a2 s.co m*/ String price = null; BigDecimal sinIVA = detalle.getProducto().getPrecioVenta().subtract(detalle.getProducto() .getPrecioVenta().multiply(new BigDecimal(17.35)).divide(new BigDecimal(100))); price = sinIVA.setScale(4, RoundingMode.HALF_UP).toString(); ticket.println("B" + (char) 28 /*Abrimos linea*/ + detalle.getProducto().getDescripcion() + (char) 28 /*Nombre producto*/ + detalle.getCantidadDetalle() + ".0" + (char) 28 /*Cantidad*/ + price.replace(",", ".") + (char) 28 /*Precio unitario*/ + "21.0" + (char) 28 /*Impuestos IVA*/ + "M" + (char) 28 /*Suma monto*/ + "0.0" + (char) 28 /*Impuestos internos*/ + "0" + (char) 28 /*Parametro display*/ + "b"); /*Cierra de linea*/ } if (!descuento.equals(new BigDecimal(BigInteger.ZERO))) { ticket.println("T" + (char) 28 /*Abrimos linea descuento*/ + "Descuento: " + (char) 28 /*Texto a mostrar*/ + descuento + (char) 28 /*Monto descuento*/ + "m" + (char) 28 /*m: descuento, M: aumento*/ + "0" + (char) 28 /*parametro display*/ + "T"); /*cierre linea descuento*/ } ticket.println("E"); } catch (FileNotFoundException ex) { Logger.getLogger(FiscalDAOImpl.class.getName()).log(Level.SEVERE, null, ex); } }