List of usage examples for java.text DecimalFormat setMaximumFractionDigits
@Override public void setMaximumFractionDigits(int newValue)
From source file:com.ar.dev.tierra.api.dao.impl.FiscalDAOImpl.java
@Override public void factura_a(List<DetalleFactura> detalles, Cliente cliente) { try (PrintWriter ticket = new PrintWriter("command/factura_a.200")) { DecimalFormat decimalFormat = new DecimalFormat(); decimalFormat.setMaximumFractionDigits(1); ticket.println("b" + (char) 28 + cliente.getNombreCliente() + (char) 28 + cliente.getDocumento() + (char) 28 + cliente.getResponsabilidadIva() + (char) 28 + cliente.getTipoDocumento() + (char) 28 + cliente.getDomicilio()); ticket.println("@" + (char) 28 + "A" + (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 . ja v a 2 s. c o 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); } }
From source file:com.ar.dev.tierra.api.dao.impl.FiscalDAOImpl.java
@Override public void factura_b(List<DetalleFactura> detalles, Cliente cliente) { try (PrintWriter ticket = new PrintWriter("command/factura_b.200")) { DecimalFormat decimalFormat = new DecimalFormat(); decimalFormat.setMaximumFractionDigits(1); ticket.println("b" + (char) 28 + cliente.getNombreCliente() + (char) 28 + cliente.getDocumento() + (char) 28 + cliente.getResponsabilidadIva() + (char) 28 + cliente.getTipoDocumento() + (char) 28 + cliente.getDomicilio()); ticket.println("@" + (char) 28 + "B" + (char) 28 + "T"); BigDecimal descuento = new BigDecimal(BigInteger.ZERO); for (DetalleFactura detalle : detalles) { if (detalle.getDescuentoDetalle() != null) { descuento = descuento.add(detalle.getDescuentoDetalle()); }//from ww w .j a v a 2s . c o 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); } }
From source file:org.onebusaway.nextbus.actions.api.VehicleLocationsAction.java
private List<Vehicle> getVehiclesForRoute(String routeId, ListBean<TripDetailsBean> trips) { DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(6); List<Vehicle> vehiclesList = new ArrayList<Vehicle>(); for (TripDetailsBean tripDetails : trips.getList()) { TripStatusBean tripStatus = tripDetails.getStatus(); // filter out interlined routes if (routeId != null && !tripDetails.getTrip().getRoute().getId().equals(routeId)) continue; Vehicle vehicle = new Vehicle(); String vehicleId = null;// w w w . j a va 2s . co m if (tripStatus.getVehicleId() != null) { vehicleId = getIdNoAgency(tripStatus.getVehicleId()); } else continue; vehicle.setId(vehicleId); vehicle.setLat(new BigDecimal(df.format(tripStatus.getLocation().getLat()))); vehicle.setLon(new BigDecimal(df.format(tripStatus.getLocation().getLon()))); vehicle.setHeading((int) tripStatus.getOrientation()); vehicle.setDirTag(tripStatus.getActiveTrip().getDirectionId()); vehicle.setPredictable(tripStatus.isPredicted()); vehicle.setRouteTag(getIdNoAgency(tripStatus.getActiveTrip().getRoute().getId())); vehicle.setTripTag(getIdNoAgency(tripStatus.getActiveTrip().getId())); vehicle.setBlock(getIdNoAgency(tripStatus.getActiveTrip().getBlockId())); int secondsSinceUpdate = 0; if (tripStatus.getLastUpdateTime() > 0) secondsSinceUpdate = (int) TimeUnit.MILLISECONDS .toSeconds(SystemTime.currentTimeMillis() - tripStatus.getLastUpdateTime()); vehicle.setSecsSinceReport(secondsSinceUpdate); vehiclesList.add(vehicle); } return vehiclesList; }
From source file:org.intermine.bio.dataconversion.FlyAtlasConverter.java
private String round(String num, int dp) { double d = Double.parseDouble(num); DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(); format.setMaximumFractionDigits(dp); format.setGroupingUsed(false);/* ww w .j a va 2s . co m*/ return format.format(d); }
From source file:org.opensingular.form.wicket.mapper.DecimalMapper.java
private String formatDecimal(BigDecimal bigDecimal, boolean groupingUsed) { DecimalFormat nf = (DecimalFormat) DecimalFormat.getInstance(new Locale("pt", "BR")); nf.setParseBigDecimal(true);// w w w.j av a 2 s . co m nf.setGroupingUsed(groupingUsed); nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(bigDecimal.scale()); return nf.format(bigDecimal); }
From source file:org.arkanos.aos.api.data.Task.java
@Override public String toString() { DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(1); df.setGroupingUsed(false);/*from w w w .j a v a2 s . com*/ String result = "{\""; result += Task.FIELD_ID + "\":" + this.id + ",\""; result += Task.FIELD_GOAL_ID + "\":" + this.goal_id + ",\""; result += Task.FIELD_NAME + "\":\"" + this.name + "\",\""; result += Task.FIELD_INITIAL + "\":" + df.format(this.initial) + ",\""; result += Task.EXTRA_CURRENT + "\":" + df.format(this.current) + ",\""; result += Task.EXTRA_TOTAL_TIME_SPENT + "\":" + df.format(this.total_time_spent / 60.0f) + ",\""; result += Task.EXTRA_COMPLETION + "\":" + df.format(this.completion * 100.0f) + ",\""; result += Task.EXTRA_GOAL_TITLE + "\":\"" + this.goal_title + "\",\""; result += Task.FIELD_TARGET + "\":" + this.target + "}"; return result; }
From source file:org.opensingular.form.wicket.mapper.MoneyMapper.java
private String formatDecimal(BigDecimal bigDecimal, Integer casasDecimais) { DecimalFormat nf = (DecimalFormat) DecimalFormat.getInstance(new Locale("pt", "BR")); nf.setParseBigDecimal(true);//from w w w . ja v a2s . c om nf.setGroupingUsed(true); nf.setMinimumFractionDigits(casasDecimais); nf.setMaximumFractionDigits(casasDecimais); return nf.format(bigDecimal); }
From source file:org.sakaiproject.tool.assessment.data.dao.grading.MediaData.java
public String getFileSizeKBFormat() { String fileSizeKBStr = ""; if (fileSize != null) { double fileSizeKB = fileSize.doubleValue() / 1000; DecimalFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setDecimalSeparatorAlwaysShown(true); fileSizeKBStr = nf.format(fileSizeKB); }/* w ww . jav a 2 s . co m*/ return fileSizeKBStr; }
From source file:distributions.Gamma.java
public void generateDistributionCSVFile() { try {/*from ww w . j ava 2s. c o m*/ try (FileWriter writer = new FileWriter( "C:\\Users\\Sinan\\Desktop\\FinalThesisTest\\ValidationSet\\test_gauss.csv", true)) { for (int i = 0; i < data.length; i++) { String s; DecimalFormat df = new DecimalFormat("0.###########"); df.setMaximumFractionDigits(12); s = df.format(Prob[i]); //data[i][j]=((data[i][j])*(max[j]-min[j]))+min[j]; //writer.append(String.valueOf(i+1)); //writer.append(','); writer.append(s); writer.append('\n'); } writer.flush(); } } catch (IOException e) { e.printStackTrace(); } }
From source file:MondrianConnector.java
public ArrayList<LinkedHashMap<String, String>> ExecuteQuery(Query queryObject) throws Exception { System.setProperty("mondrian.olap.SsasCompatibleNaming", "true"); String connectionString = getConnectionString(queryObject); RolapConnection connection = (RolapConnection) DriverManager.getConnection(connectionString, null); mondrian.olap.Query query = connection.parseQuery(queryObject.getMdxQuery()); Result result = connection.execute(query); ArrayList<LinkedHashMap<String, String>> data = new ArrayList<LinkedHashMap<String, String>>(); DecimalFormat df = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); df.setMaximumFractionDigits(340); //340 = DecimalFormat.DOUBLE_FRACTION_DIGITS if (result.getAxes().length == 1) { //Only One Axis has come so ArrayList<String> measures = new ArrayList<String>(); for (Position p : result.getAxes()[0].getPositions()) { measures.add(p.get(0).getUniqueName().toString()); }/*w w w. j av a 2s .co m*/ LinkedHashMap<String, String> row = new LinkedHashMap<String, String>(); for (int i = 0; i < measures.size(); i++) { Object value = result.getCell(new int[] { i }).getValue(); if (value == null) { row.put(measures.get(i), null); } else if (value instanceof Integer) { row.put(measures.get(i), ((Integer) value).toString()); } else if (value instanceof Double) { row.put(measures.get(i), df.format(value)); } else { row.put(measures.get(i), value.toString()); } } data.add(row); } else if (result.getAxes().length == 2) { ArrayList<String> measures = new ArrayList<String>(); for (Position p : result.getAxes()[0].getPositions()) { measures.add(p.get(0).getUniqueName().toString()); } ArrayList<ArrayList<DimensionItem>> dimensionItems = new ArrayList<ArrayList<DimensionItem>>(); for (Position p : result.getAxes()[1].getPositions()) { ArrayList<DimensionItem> itemsAtRow = new ArrayList<DimensionItem>(); for (Object item : p.toArray()) { RolapMemberBase member = (RolapMemberBase) item; itemsAtRow.add(new DimensionItem(member.getLevel().getHierarchy().toString(), member.getCaption().toString())); } dimensionItems.add(itemsAtRow); } for (int ix = 0; ix < dimensionItems.size(); ix++) { LinkedHashMap<String, String> row = new LinkedHashMap<String, String>(); for (DimensionItem item : dimensionItems.get(ix)) { row.put(item.getLevel(), item.getCaption()); } for (int i = 0; i < measures.size(); i++) { Object value = result.getCell(new int[] { i, ix }).getValue(); if (value == null) { row.put(measures.get(i), "0"); } else { if (value instanceof Integer) { row.put(measures.get(i), ((Integer) value).toString()); } else if (value instanceof Double) { row.put(measures.get(i), df.format(value)); } else { row.put(measures.get(i), value.toString()); } } } data.add(row); } } return data; }