List of usage examples for java.text DecimalFormat DecimalFormat
public DecimalFormat(String pattern)
From source file:com.swcguild.springmvcwebapp.controller.TipCalcController.java
@RequestMapping(value = "/tipCalc", method = RequestMethod.POST) public String calculateTip(HttpServletRequest request, Model model) { try {/*from w w w . j a v a 2s. c o m*/ originalAmount = Double.parseDouble(request.getParameter("originalAmount")); tipPercentage = Double.parseDouble(request.getParameter("tipPercentage")); tipAmount = (tipPercentage * originalAmount) / 100; finalAmount = originalAmount + tipAmount; DecimalFormat df = new DecimalFormat("#.00"); model.addAttribute("originalAmount", df.format(originalAmount)); model.addAttribute("tipAmount", df.format(tipAmount)); model.addAttribute("tipPercentage", tipPercentage); model.addAttribute("finalAmount", df.format(finalAmount)); } catch (NumberFormatException e) { } return "tipCalcResponse"; }
From source file:eu.fbk.utils.lsa.util.AnvurDev.java
public static void main(String[] args) throws Exception { String logConfig = System.getProperty("log-config"); if (logConfig == null) { logConfig = "log-config.txt"; }/*w w w .jav a2 s . c o m*/ PropertyConfigurator.configure(logConfig); if (args.length != 8) { System.out.println(args.length); System.out.println( "Usage: java -mx2G eu.fbk.utils.lsa.util.AnvurDev root-lsa-en root-lsa-it threshold-lsa size-lsa dim-lsa idf-lsa in-file-tsv fields-tsv\n\n"); System.exit(1); } // DecimalFormat dec = new DecimalFormat("#.00"); File enUt = new File(args[0] + "-Ut"); File enSk = new File(args[0] + "-S"); File enr = new File(args[0] + "-row"); File enc = new File(args[0] + "-col"); File endf = new File(args[0] + "-df"); File itUt = new File(args[1] + "-Ut"); File itSk = new File(args[1] + "-S"); File itr = new File(args[1] + "-row"); File itc = new File(args[1] + "-col"); File itdf = new File(args[1] + "-df"); double threshold = Double.parseDouble(args[2]); int size = Integer.parseInt(args[3]); int dim = Integer.parseInt(args[4]); boolean rescaleIdf = Boolean.parseBoolean(args[5]); LSM enLsm = new LSM(enUt, enSk, enr, enc, endf, dim, rescaleIdf); LSM itLsm = new LSM(itUt, itSk, itr, itc, itdf, dim, rescaleIdf); File in = new File(args[6]); if (in.isFile()) { run(enLsm, itLsm, args[6], args[7]); } else if (in.isDirectory()) { FolderScanner fs = new FolderScanner(in); fs.setFiler(new TsvFilter()); int count = 0; while (fs.hasNext()) { Object[] files = fs.next(); System.out.println((count++) + " : " + files.length); for (int i = 0; i < files.length; i++) { String name = ((File) files[i]).getAbsolutePath(); System.out.println(name); run(enLsm, itLsm, name, args[7]); } // end for i } // end while } }
From source file:eu.fbk.utils.analysis.stemmer.AbstractStemmer.java
public AbstractStemmer(int size) { //cache = new LRUMap(size); df = new DecimalFormat("000,000,000.#"); }
From source file:org.jfree.chart.demo.StackedXYBarChartDemo3.java
private static JFreeChart createChart(TableXYDataset tablexydataset) { DateAxis dateaxis = new DateAxis("Year"); dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); dateaxis.setLowerMargin(0.01D);//from ww w . j a va2s.c o m dateaxis.setUpperMargin(0.01D); NumberAxis numberaxis = new NumberAxis("Tonnes"); numberaxis.setNumberFormatOverride(new DecimalFormat("0.0%")); StackedXYBarRenderer stackedxybarrenderer = new StackedXYBarRenderer(0.29999999999999999D); stackedxybarrenderer.setRenderAsPercentages(true); GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, new Color(64, 0, 0), 0.0F, 0.0F, Color.red); GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, new Color(0, 64, 0), 0.0F, 0.0F, Color.green); stackedxybarrenderer.setSeriesPaint(0, gradientpaint); stackedxybarrenderer.setSeriesPaint(1, gradientpaint1); stackedxybarrenderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); stackedxybarrenderer.setDrawBarOutline(false); stackedxybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} : {1} = {2} tonnes", new SimpleDateFormat("yyyy"), new DecimalFormat("#,##0"))); XYPlot xyplot = new XYPlot(tablexydataset, dateaxis, numberaxis, stackedxybarrenderer); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); JFreeChart jfreechart = new JFreeChart("Waste Management", xyplot); jfreechart.setBackgroundPaint(Color.white); jfreechart.addSubtitle(new TextTitle("St Albans City and District Council")); return jfreechart; }
From source file:com.wuliu.biz.util.WuliuMemberUtil.java
public static WuliuMemberModel convertToWuliuMemberModel(WuliuMemberDO wuliuMemberDO) { if (wuliuMemberDO == null) { return null; }/*from w w w .j ava 2 s . co m*/ WuliuMemberModel ret = new WuliuMemberModel(); ret.setAddress(wuliuMemberDO.getAddress()); ret.setId(wuliuMemberDO.getId()); ret.setMobileNumber(wuliuMemberDO.getMobileNumber()); ret.setName(wuliuMemberDO.getName()); ret.setNickName(wuliuMemberDO.getNickName()); ret.setStatus(wuliuMemberDO.getStatus()); ret.setTelephoneNumber(wuliuMemberDO.getTelephoneNumber()); ret.setVolumnPrice(wuliuMemberDO.getVolumnPrice()); ret.setWeightPrice(wuliuMemberDO.getWeightPrice()); ret.setShopAddress(wuliuMemberDO.getShopAddress()); DecimalFormat df = new DecimalFormat("0.##"); if (ret.getWeightPrice() != null) { ret.setWeightPriceForDisplay(df.format(ret.getWeightPrice() / 100.0)); } if (ret.getVolumnPrice() != null) { ret.setVolumnPriceForDisplay(df.format(ret.getVolumnPrice() / 100.0)); } return ret; }
From source file:org.jfree.chart.demo.WaterfallChartDemo1.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createWaterfallChart("Product Cost Breakdown", "Expense Category", "Cost Per Unit", categorydataset, PlotOrientation.VERTICAL, false, true, false); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); categoryplot.setRangeGridlinesVisible(true); categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); ValueAxis valueaxis = categoryplot.getRangeAxis(); DecimalFormat decimalformat = new DecimalFormat("##,###"); decimalformat.setNegativePrefix("("); decimalformat.setNegativeSuffix(")"); TickUnits tickunits = new TickUnits(); tickunits.add(new NumberTickUnit(5D, decimalformat)); tickunits.add(new NumberTickUnit(10D, decimalformat)); tickunits.add(new NumberTickUnit(20D, decimalformat)); tickunits.add(new NumberTickUnit(50D, decimalformat)); tickunits.add(new NumberTickUnit(100D, decimalformat)); tickunits.add(new NumberTickUnit(200D, decimalformat)); tickunits.add(new NumberTickUnit(500D, decimalformat)); tickunits.add(new NumberTickUnit(1000D, decimalformat)); tickunits.add(new NumberTickUnit(2000D, decimalformat)); tickunits.add(new NumberTickUnit(5000D, decimalformat)); valueaxis.setStandardTickUnits(tickunits); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setDrawBarOutline(false); barrenderer.setBase(5D);/*from ww w. ja v a 2 s. c o m*/ DecimalFormat decimalformat1 = new DecimalFormat("$##,###.00"); decimalformat1.setNegativePrefix("("); decimalformat1.setNegativeSuffix(")"); barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1)); barrenderer.setBaseItemLabelsVisible(true); return jfreechart; }
From source file:com.github.ukase.toolkit.helpers.FormatNumberHelper.java
@Override public CharSequence apply(Number context, Options options) throws IOException { if (context == null) { return ""; }//ww w. ja va2 s . c o m String format = options.param(0, ""); if (format.trim().length() == 0) { return ""; } return new DecimalFormat(format).format(context); }
From source file:com.hadoop.compression.lzo.LzoIndexer.java
public LzoIndexer(Configuration conf) { conf_ = conf; df_ = new DecimalFormat("#0.00"); }
From source file:guineu.modules.visualization.intensityplot.IntensityPlotTooltipGenerator.java
/** * @see org.jfree.chart.labels.CategoryToolTipGenerator#generateToolTip(org.jfree.data.category.CategoryDataset, * int, int)//from ww w . ja v a 2 s . c om */ public String generateToolTip(CategoryDataset dataset, int row, int column) { Format intensityFormat = new DecimalFormat("0.0E0"); Double peaks[] = ((IntensityPlotDataset) dataset).getPeaks(row, column); String files[] = ((IntensityPlotDataset) dataset).getFiles(column); StringBuilder sb = new StringBuilder(); for (int i = 0; i < files.length; i++) { sb.append(files[i].toString()); sb.append(": "); if (peaks[i] != null) { sb.append("height: "); sb.append(intensityFormat.format(peaks[i])); } else { sb.append("N/A"); } sb.append("\n"); } return sb.toString(); }
From source file:net.jofm.format.NumberFormat.java
@Override protected Object doParse(String value, Class<?> destinationClazz) { Number result;/* w w w . j a v a 2s .co m*/ try { if (StringUtils.isNotEmpty(format)) { DecimalFormat formatter = new DecimalFormat(format); result = formatter.parse(value); } else { result = Double.valueOf(value); } } catch (Exception pe) { throw new FixedMappingException( "Unable to parse the value '" + value + "' to number with format '" + format + "'"); } return convert(result, destinationClazz); }