List of usage examples for java.text DecimalFormat DecimalFormat
public DecimalFormat(String pattern)
From source file:org.moserp.billing.domain.Bill.java
public String calculateNumber(int billCounter) { NumberFormat format = new DecimalFormat("00"); return saleDate.getYear() + "/" + format.format(saleDate.getMonth().getValue()) + format.format(billCounter); }
From source file:com.swcguild.springmvcwebapp.controller.InterCalcController.java
@RequestMapping(value = "/intercalc", method = RequestMethod.POST) public String doPost(HttpServletRequest request, Model model) { try {/*from w ww. ja va 2 s.c o m*/ originalBalance = Double.parseDouble(request.getParameter("myAnswer")); startingBalance = originalBalance; intRate = Double.parseDouble(request.getParameter("myRate")); numYears = Double.parseDouble(request.getParameter("myYears")); numPeriods = Double.parseDouble(request.getParameter("myPeriods")); message = ""; //totalInterest; //newBalance; //List<Map> annualInterest = new ArrayList<>(); Map yearMap = new HashMap<>(); DecimalFormat df = new DecimalFormat("#.00"); int yearCount = 0; do { newBalance = originalBalance * (Math.pow(1 + ((intRate * .01) / numPeriods), (numPeriods))); yearCount++; double interestPerYear = newBalance - originalBalance; String interestPerYearString = df.format(interestPerYear); yearMap.put(yearCount, interestPerYearString); originalBalance = newBalance; } while (yearCount <= (numYears - 1)); totalInterest = newBalance - startingBalance; //annualInterest.add(yearMap); String annualInterestString = yearMap.toString().replace("{", "").replace("}", "").trim(); model.addAttribute("originalBalance", df.format(startingBalance)); model.addAttribute("newBalance", df.format(newBalance)); model.addAttribute("interestRate", intRate); model.addAttribute("interestEarned", df.format(totalInterest)); model.addAttribute("years", df.format(numYears)); model.addAttribute("periods", df.format(numPeriods)); model.addAttribute("annualInterest", yearMap); } catch (NumberFormatException e) { } return "intercalcResponse"; //<td><c:out value="${current.id}" /><td> }
From source file:com.bigml.histogram.Bin.java
@Override public String toString() { return toJSON(new DecimalFormat(Histogram.DEFAULT_FORMAT_STRING)).toJSONString(); }
From source file:com.eurotong.orderhelperandroid.Common.java
static public String FormatDouble(double inputvalue) { String value = "UNKNOWN"; int sign = 1; if (inputvalue < 0) { sign = -1;// w ww . j a v a 2 s .c o m } inputvalue = inputvalue * sign; if (inputvalue == 0) { return "0" + Setting.Current().getComma() + "00"; } if (inputvalue < 0.1) { Common.GetToastLong("format double error: " + inputvalue).show(); } else { value = new DecimalFormat("#").format(inputvalue * 100); //Double.toString(inputvalue * 100); String comma = Setting.Current().getComma(); value = value.substring(0, value.length() - 2) + comma + value.substring(value.length() - 2, value.length()); if (value.length() == 3) value = "0" + value; if (sign < 1) { value = "-" + value; } } return value; }
From source file:com.krawler.common.util.BaseStringUtil.java
public static String sizeRenderer(String value) { Double size = Double.parseDouble(value); String text = ""; Double val; DecimalFormat decimalFormat = new DecimalFormat("#.##"); if (size >= 1 && size < 1024) { text = size + " Bytes"; } else if (size > 1024 && size < 1048576) { val = (size / 1024); text = decimalFormat.format(val); text += " KB"; } else if (size > 1048576) { val = (size / 1048576); text = decimalFormat.format(val); text += " MB"; }// w ww .j av a 2 s .c om return text; }
From source file:GeMSE.GS.Analysis.Stats.TwoSampleTTestPanel.java
public TwoSampleTTestPanel() { initComponents();/*w ww .j a v a 2 s. c om*/ _sample1 = new double[0]; _sample2 = new double[0]; _decFor = new DecimalFormat("#.#########"); _decFor.setRoundingMode(RoundingMode.CEILING); DecimalFormatSymbols decFors = _decFor.getDecimalFormatSymbols(); decFors.setNaN("NaN"); decFors.setInfinity(""); _decFor.setDecimalFormatSymbols(decFors); _variance = new Variance(); _studentTest = new TTest(); }
From source file:Interfaz.adminZone.java
private void llenar() { NumberFormat formatter = new DecimalFormat("###.###"); String select = " (Cl.nombre)Nombre,(SUM(Va.Cantidad*Acc.precio)+SUM(Vc.Cantidad*Com.precio)+ " + " SUM(Vb.Cantidad*Bi.precio))'Dinero Gastado', " + " CASE WHEN (SUM(Va.Cantidad*Acc.precio)+SUM(Vc.Cantidad*Com.precio)+ " + " SUM(Vb.Cantidad*Bi.precio))>(SELECT AVG(VV) " + " FROM (SELECT (SUM(Vaa.Cantidad*Ac.precio)+SUM(Vcc.Cantidad*Comm.precio)+ " + "SUM(Vbb.Cantidad*Bii.precio)) AS VV " + " " + " FROM Venta_Accesorio Vaa " + "INNER JOIN Accesorio Ac " + "INNER JOIN Venta Ve " + "INNER JOIN Cliente Cll " + "INNER JOIN Venta_Componente Vcc " + "INNER JOIN Componente Comm " + "INNER JOIN Venta_Bicleta Vbb " + "INNER JOIN Bicicleta Bii " + "ON Vaa.refaccesorio=Ac.referencia AND Vcc.refcomponente=Comm.referencia AND Vbb.refbicicleta=Bii.referencia " + "AND Ve.idventa=Vaa.idventa AND Ve.idventa=Vcc.idventa " + "AND Ve.idventa=Vbb.idventa AND Ve.Cliente=Cll.Documento " + "GROUP BY Cll.Documento)TAB)THEN 'Cliente Premium' ELSE 'Cliente Normal' END TipoCliente"; String tabla = " Venta_Accesorio Va "; String condicion = "INNER JOIN Accesorio Acc " + "INNER JOIN Venta V " + "INNER JOIN Cliente Cl " + "INNER JOIN Venta_Componente Vc " + "INNER JOIN Componente Com " + "INNER JOIN Venta_Bicleta Vb " + "INNER JOIN Bicicleta Bi " + "ON Va.refaccesorio=Acc.referencia " + "AND Vc.refcomponente=Com.referencia " + "AND Vb.refbicicleta=Bi.referencia " + "AND V.idventa=Va.idventa " + "AND V.idventa=Vc.idventa " + "AND V.idventa=Vb.idventa " + "AND V.Cliente=Cl.documento " + "GROUP BY Cl.Documento"; this.con.llenarTabla(select, tabla, 3, modeloCliDes, condicion); for (int i = 0; i < this.modeloCliDes.getRowCount(); i++) { ;/* w w w . java2 s. co m*/ this.modeloCliDes.setValueAt(formatter.format(this.modeloCliDes.getValueAt(i, 1)), i, 1); } select = "MONTH(Fecha) Mes, SUM(ValorTotal)"; condicion = "GROUP BY Mes"; con.llenarTabla(select, "Venta", 2, modeloVentasMes, condicion); con.llenarCB("E.Nombre", "Venta", "INNER JOIN Empleado E ON E.Documento = Venta.Empleado " + "INNER JOIN Cargo C ON E.Cargo = C.IdCargo " + "GROUP BY Empleado", modeloEmp); }
From source file:io.hops.hopsworks.common.util.FormatUtils.java
public static String storage(Long s) { DecimalFormat format = new DecimalFormat("#.#"); Double size = (double) s; if (size < K) { return format.format(size) + " B"; }//from ww w . ja v a 2 s . c om if (size < M) { return format.format(size / K) + " KB"; } if (size < G) { return format.format(size / M) + " MB"; } if (size < T) { return format.format(size / G) + " GB"; } return format.format(size / T) + " TB"; }
From source file:com.skilrock.lms.web.scratchService.inventoryMgmt.common.AgentOrderProcessAction.java
private static String roundTo2DecimalPlaces(double value) { DecimalFormat df = new DecimalFormat("0.000"); String doublevalue = df.format(value); System.out.println("------kfkdjd" + doublevalue + "--------"); return doublevalue; }
From source file:com.anite.antelope.modules.tools.FormatterTool.java
public String getFormattedMoney(Double value) { DecimalFormat nf = new DecimalFormat("##,###,##0.00"); return nf.format(value); }