List of usage examples for java.text NumberFormat getInstance
public static NumberFormat getInstance(Locale inLocale)
From source file:com.safetys.framework.jmesa.core.filter.NumberFilterMatcher.java
public boolean evaluate(Object itemValue, String filterValue) { if (itemValue == null) { return false; }/* w w w .java 2s. co m*/ Locale locale = null; WebContext webContext = getWebContext(); if (webContext != null) { locale = webContext.getLocale(); } NumberFormat nf; if (locale != null) { nf = NumberFormat.getInstance(locale); } else { nf = NumberFormat.getInstance(); } DecimalFormat df = (DecimalFormat) nf; String pattern = getPattern(); df.applyPattern(pattern); itemValue = df.format(itemValue); String item = String.valueOf(itemValue); String filter = String.valueOf(filterValue); if (StringUtils.contains(item, filter)) { return true; } return false; }
From source file:cherry.foundation.render.ObjectRendererImpl.java
@Override public String render(Object value, Integer mode) { if (value == null) { return ""; } else if (value instanceof Number) { Locale locale = LocaleContextHolder.getLocale(); if (CollectionUtils.isEmpty(numberFormatter)) { return NumberFormat.getInstance(locale).format(value); } else {/*from www.jav a2s. co m*/ return getSafe(numberFormatter, mode).getNumberFormat(locale).format(value); } } else if (value instanceof LocalDate) { return conversionService.convert(value, String.class); } else if (value instanceof LocalTime) { return conversionService.convert(value, String.class); } else if (value instanceof LocalDateTime) { return conversionService.convert(value, String.class); } else if (value instanceof String) { return (String) value; } else { return value.toString(); } }
From source file:net.sf.jasperreports.charts.util.XYDatasetLabelGenerator.java
public XYDatasetLabelGenerator(Map<Comparable<?>, Map<Number, String>> labelsMap, Locale locale) { super(DEFAULT_ITEM_LABEL_FORMAT, NumberFormat.getInstance(locale), NumberFormat.getInstance(locale)); this.labelsMap = labelsMap; }
From source file:com.salesmanager.core.module.impl.application.currencies.USDCurrencyModule.java
public String getMeasure(BigDecimal measure, String currencycode) throws Exception { NumberFormat nf = null;//from w ww . j a va 2s . c om nf = NumberFormat.getInstance(Locale.US); nf.setMaximumFractionDigits(1); nf.setMinimumFractionDigits(1); measure.setScale(1, BigDecimal.ROUND_HALF_UP); return nf.format(measure); }
From source file:com.salesmanager.core.module.impl.application.currencies.EURCurrencyModule.java
public String getMeasure(BigDecimal measure, String currencycode) throws Exception { NumberFormat nf = null;//w w w. j a va2 s .c o m nf = NumberFormat.getInstance(Locale.GERMAN); nf.setMaximumFractionDigits(1); nf.setMinimumFractionDigits(1); measure.setScale(1, BigDecimal.ROUND_HALF_UP); return nf.format(measure); }
From source file:net.sf.jasperreports.charts.util.TimePeriodDatasetLabelGenerator.java
public TimePeriodDatasetLabelGenerator(Map<Comparable<?>, Map<TimePeriod, String>> labelsMap, Locale locale) { super(DEFAULT_ITEM_LABEL_FORMAT, NumberFormat.getInstance(locale), NumberFormat.getInstance(locale)); this.labelsMap = labelsMap; }
From source file:net.sf.jasperreports.charts.util.TimeSeriesLabelGenerator.java
public TimeSeriesLabelGenerator(Map<Comparable<?>, Map<RegularTimePeriod, String>> labelsMap, Locale locale) { super(DEFAULT_ITEM_LABEL_FORMAT, NumberFormat.getInstance(locale), NumberFormat.getInstance(locale)); this.labelsMap = labelsMap; }
From source file:logic.Export.java
public boolean convertXls() throws IOException, FileNotFoundException, IllegalArgumentException, ParseException { FileInputStream tamplateFile = new FileInputStream(templatePath); XSSFWorkbook workbook = new XSSFWorkbook(tamplateFile); CellStyle cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("#,##")); double hours = 0.0; NumberFormat format = NumberFormat.getInstance(Locale.FRANCE); Number number;//from w w w . j av a 2 s .c om XSSFSheet sheet; XSSFSheet sheet2; Cell cell = null; ConvertData cd = new ConvertData(); for (int i = 0; i < cd.getSheetnames().size(); i++) { sheet2 = workbook.cloneSheet(0, cd.sheetnames.get(i)); sheet = workbook.getSheetAt(i + 1); //formate sheets sheet.getPrintSetup().setLandscape(true); sheet.getPrintSetup().setPaperSize(HSSFPrintSetup.A4_PAPERSIZE); cell = sheet.getRow(0).getCell(1); cell.setCellValue(cd.sheetnames.get(i)); ArrayList<String[]> convert = cd.convert(cd.sheetnames.get(i)); //setPrintArea workbook.setPrintArea(i + 1, //sheet index 0, //start column Spalte 6, //end column 0, //start row zeile convert.size() + 8 //end row ); for (int Row = 0; Row < convert.size(); Row++) { for (int Cell = 0; Cell < convert.get(Row).length; Cell++) { cell = sheet.getRow(9 + Row).getCell(Cell); if (Cell == 3) { if ("true".equals(convert.get(Row)[Cell])) { XSSFCellStyle style1 = workbook.createCellStyle(); style1 = (XSSFCellStyle) cell.getCellStyle(); style1 = (XSSFCellStyle) style1.clone(); style1.setFillBackgroundColor(HSSFColor.RED.index); style1.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); XSSFColor myColor = new XSSFColor(Color.RED); style1.setFillForegroundColor(myColor); sheet.getRow(9 + Row).getCell(6).setCellStyle(style1); } } else { cell.setCellValue(convert.get(Row)[Cell]); } } } } workbook.removeSheetAt(0); tamplateFile.close(); File exportFile = newPath.getSelectedFile(); if (FilenameUtils.getExtension(exportFile.getName()).equalsIgnoreCase("xlsx")) { } else { exportFile = new File(exportFile.getParentFile(), FilenameUtils.getBaseName(exportFile.getName()) + ".xlsx"); } FileOutputStream outFile = new FileOutputStream(exportFile); workbook.write(outFile); outFile.close(); tamplateFile.close(); return true; }
From source file:by.creepid.docsreporter.context.DocContextProcessorTest.java
public DocContextProcessorTest() { Locale locale = Locale.getDefault(); decimalFormatter = (DecimalFormat) NumberFormat.getInstance(locale); DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale); symbols.setDecimalSeparator(','); symbols.setGroupingSeparator(' '); decimalFormatter.setDecimalFormatSymbols(symbols); dateFormat = new SimpleDateFormat("dd.MM.yyyy"); }
From source file:org.zilverline.web.IndexDefaultsController.java
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { super.initBinder(request, binder); NumberFormat nf = NumberFormat.getInstance(request.getLocale()); binder.registerCustomEditor(java.lang.Integer.class, new CustomNumberEditor(java.lang.Integer.class, nf, true)); }