List of usage examples for java.text NumberFormat getNumberInstance
public static NumberFormat getNumberInstance(Locale inLocale)
From source file:com.qcadoo.model.internal.types.DecimalTypeTest.java
@Before public final void init() { MockitoAnnotations.initMocks(this); decimalType = new DecimalType(); numberFormat = NumberFormat.getNumberInstance(locale); numberFormat.setMaximumFractionDigits(Integer.MAX_VALUE); numberFormat.setMaximumIntegerDigits(Integer.MAX_VALUE); }
From source file:whitelabel.cloud.adapter.CurrencyFormatterExt.java
public NumberFormat getNumberFormat(Locale locale, String pattern) { NumberFormat df = NumberFormat.getNumberInstance(locale); DecimalFormat dec = (DecimalFormat) df; dec.applyPattern(pattern);//from ww w. j a v a2s . c om dec.setMaximumFractionDigits(2); dec.setGroupingUsed(false); return dec; }
From source file:net.sf.jasperreports.charts.util.CategoryLabelGenerator.java
public CategoryLabelGenerator(Map<Comparable<?>, Map<Comparable<?>, String>> labelsMap, Locale locale) { super(DEFAULT_LABEL_FORMAT_STRING, NumberFormat.getNumberInstance(locale), NumberFormat.getPercentInstance(locale)); this.labelsMap = labelsMap; }
From source file:easyJ.common.validate.GenericTypeValidator.java
/** * Checks if the value can safely be converted to a byte primitive. * //from www . jav a 2s . c o m * @param value * The value validation is being performed on. * @param locale * The locale to use to parse the number (system default if * null) * @return the converted Byte value. */ public static Byte formatByte(String value, Locale locale) { Byte result = null; if (value != null) { NumberFormat formatter = null; if (locale != null) { formatter = NumberFormat.getNumberInstance(locale); } else { formatter = NumberFormat.getNumberInstance(Locale.getDefault()); } formatter.setParseIntegerOnly(true); ParsePosition pos = new ParsePosition(0); Number num = formatter.parse(value, pos); // If there was no error and we used the whole string if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { if (num.doubleValue() >= Byte.MIN_VALUE && num.doubleValue() <= Byte.MAX_VALUE) { result = new Byte(num.byteValue()); } } } return result; }
From source file:capital.scalable.restdocs.jackson.BigDecimalSerializer.java
private DecimalFormat englishDecimalFormat() { DecimalFormat df = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ENGLISH); df.applyPattern("#,##0.00"); return df;// w w w . j a v a2s. c o m }
From source file:org.lingcloud.molva.ocl.util.GenericTypeValidator.java
/** * Checks if the value can safely be converted to a byte primitive. * //from w w w.j ava2s. c o m * @param value * The value validation is being performed on. * @param locale * The locale to use to parse the number (system default if null) * @return the converted Byte value. */ public static Byte formatByte(String value, Locale locale) { Byte result = null; if (value != null) { NumberFormat formatter = null; if (locale != null) { formatter = NumberFormat.getNumberInstance(locale); } else { formatter = NumberFormat.getNumberInstance(Locale.getDefault()); } formatter.setParseIntegerOnly(true); ParsePosition pos = new ParsePosition(0); Number num = formatter.parse(value, pos); // If there was no error and we used the whole string if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { if (num.doubleValue() >= Byte.MIN_VALUE && num.doubleValue() <= Byte.MAX_VALUE) { result = Byte.valueOf(num.byteValue()); } } } return result; }
From source file:org.jboss.dashboard.ui.components.chart.MeterChartEditor.java
public CommandResponse actionSubmit(CommandRequest request) throws Exception { MeterChartDisplayer meterDisplayer = (MeterChartDisplayer) getDataDisplayer(); if (!meterDisplayer.getDataProvider().isReady()) return null; super.actionSubmit(request); try {// w ww .j a va 2 s. co m Locale locale = LocaleManager.currentLocale(); NumberFormat numberFormat = NumberFormat.getNumberInstance(locale); // Parse the position. String positionType = request.getRequestObject().getParameter("positionType"); if (positionType != null && !"".equals(positionType)) meterDisplayer.setPositionType(positionType); // Meter if (meterDisplayer.getType().equals("meter")) { String minValueParam = request.getRequestObject().getParameter("minValue"); String maxValueParam = request.getRequestObject().getParameter("maxValue"); String maxMeterTicksParam = request.getRequestObject().getParameter("maxMeterTicks"); String warningThresholdParam = request.getRequestObject().getParameter("meterWarningThreshold"); String criticalThresholdParam = request.getRequestObject().getParameter("meterCriticalThreshold"); if (minValueParam == null || "".equals(minValueParam.trim())) return null; if (maxValueParam == null || "".equals(maxValueParam.trim())) return null; if (warningThresholdParam == null || "".equals(warningThresholdParam.trim())) return null; if (criticalThresholdParam == null || "".equals(criticalThresholdParam.trim())) return null; if (maxMeterTicksParam == null || "".equals(maxMeterTicksParam.trim())) return null; double minValue = numberFormat.parse(minValueParam).doubleValue(); double maxValue = numberFormat.parse(maxValueParam).doubleValue(); double warningThreshold = numberFormat.parse(warningThresholdParam).doubleValue(); double criticalThreshold = numberFormat.parse(criticalThresholdParam).doubleValue(); int maxMeterTicks = numberFormat.parse(maxMeterTicksParam).intValue(); if (minValue > maxValue) return null; if (warningThreshold < minValue || warningThreshold > maxValue) return null; if (criticalThreshold < minValue || criticalThreshold > maxValue) return null; if (warningThreshold > criticalThreshold) return null; if (maxMeterTicks < 0) return null; meterDisplayer.setMaxMeterTicks(maxMeterTicks); meterDisplayer.setMinValue(minValue); meterDisplayer.setWarningThreshold(warningThreshold); meterDisplayer.setCriticalThreshold(criticalThreshold); meterDisplayer.setMaxValue(maxValue); /* Intervals descriptions. Hide them until the global legend will be available. String descripNormalInterval = request.getRequestObject().getParameter("descripNormalInterval"); String descripWarningInterval = request.getRequestObject().getParameter("descripWarningInterval"); String descripCriticalInterval = request.getRequestObject().getParameter("descripCriticalInterval"); if (descripCriticalInterval != null && !"".equals(descripCriticalInterval.trim())) meterDisplayer.setDescripCriticalInterval(descripCriticalInterval, locale); if (descripWarningInterval != null && !"".equals(descripWarningInterval.trim())) meterDisplayer.setDescripWarningInterval(descripWarningInterval, locale); if (descripNormalInterval != null && !"".equals(descripNormalInterval.trim())) meterDisplayer.setDescripNormalInterval(descripNormalInterval, locale); */ } // Thermometer else if (meterDisplayer.getType().equals("thermometer")) { String thermoLowerBoundParam = request.getRequestObject().getParameter("thermoLowerBound"); String thermoUpperBoundParam = request.getRequestObject().getParameter("thermoUpperBound"); String thermoWarningThresholdParam = request.getRequestObject() .getParameter("thermoWarningThreshold"); String thermoCriticalThresholdParam = request.getRequestObject() .getParameter("thermoCriticalThreshold"); if (thermoLowerBoundParam == null || "".equals(thermoLowerBoundParam.trim())) return null; if (thermoUpperBoundParam == null || "".equals(thermoUpperBoundParam.trim())) return null; if (thermoWarningThresholdParam == null || "".equals(thermoWarningThresholdParam.trim())) return null; if (thermoCriticalThresholdParam == null || "".equals(thermoCriticalThresholdParam.trim())) return null; double thermoLowerBound = numberFormat.parse(thermoLowerBoundParam).doubleValue(); double thermoUpperBound = numberFormat.parse(thermoUpperBoundParam).doubleValue(); double thermoWarningThreshold = numberFormat.parse(thermoWarningThresholdParam).doubleValue(); double thermoCriticalThreshold = numberFormat.parse(thermoCriticalThresholdParam).doubleValue(); if (thermoLowerBound > thermoUpperBound) return null; if (thermoWarningThreshold < thermoLowerBound || thermoWarningThreshold > thermoUpperBound) return null; if (thermoCriticalThreshold < thermoLowerBound || thermoCriticalThreshold > thermoUpperBound) return null; if (thermoWarningThreshold > thermoCriticalThreshold) return null; meterDisplayer.setThermoLowerBound(thermoLowerBound); meterDisplayer.setWarningThermoThreshold(thermoWarningThreshold); meterDisplayer.setCriticalThermoThreshold(thermoCriticalThreshold); meterDisplayer.setThermoUpperBound(thermoUpperBound); } // Dial else if (meterDisplayer.getType().equals("dial")) { String pointerTypeParam = request.getRequestObject().getParameter("pointerType"); String dialLowerBoundParam = request.getRequestObject().getParameter("dialLowerBound"); String dialUpperBoundParam = request.getRequestObject().getParameter("dialUpperBound"); String maxTicksParam = request.getRequestObject().getParameter("maxTicks"); String minorTickCountParam = request.getRequestObject().getParameter("minorTickCount"); if (pointerTypeParam == null || "".equals(pointerTypeParam.trim())) return null; if (dialLowerBoundParam == null || "".equals(dialLowerBoundParam.trim())) return null; if (dialUpperBoundParam == null || "".equals(dialUpperBoundParam.trim())) return null; if (maxTicksParam == null || "".equals(maxTicksParam.trim())) return null; if (minorTickCountParam == null || "".equals(minorTickCountParam.trim())) return null; double dialLowerBound = numberFormat.parse(dialLowerBoundParam).doubleValue(); double dialUpperBound = numberFormat.parse(dialUpperBoundParam).doubleValue(); int maxTicks = numberFormat.parse(maxTicksParam).intValue(); int minorTickCount = numberFormat.parse(minorTickCountParam).intValue(); if (dialLowerBound > dialUpperBound) return null; if (maxTicks < 0) return null; if (minorTickCount > 10) return null; meterDisplayer.setDialLowerBound(dialLowerBound); meterDisplayer.setDialUpperBound(dialUpperBound); meterDisplayer.setMaxTicks(numberFormat.parse(maxTicksParam).intValue()); meterDisplayer.setMinorTickCount(minorTickCount); } } catch (Exception e) { log.warn("Cannot parse number meter specific properties."); } return null; }
From source file:org.polymap.p4.process.CoordinateSupplier.java
public CoordinateSupplier() { nf = NumberFormat.getNumberInstance(Polymap.getSessionLocale()); nf.setMaximumIntegerDigits(100);// w w w. jav a 2 s .co m nf.setMaximumFractionDigits(2); nf.setMinimumIntegerDigits(1); nf.setMinimumFractionDigits(2); }
From source file:org.springframework.data.hadoop.store.strategy.rollover.SizeRolloverStrategy.java
private static long parseValue(final String string) { final Matcher matcher = VALUE_PATTERN.matcher(string); if (matcher.matches()) { try {/* w ww .j av a2s.c o m*/ final long value = NumberFormat.getNumberInstance(Locale.getDefault()).parse(matcher.group(1)) .longValue(); final String units = matcher.group(3); if (units.equalsIgnoreCase("")) { return value; } else if (units.equalsIgnoreCase("K")) { return value * KB; } else if (units.equalsIgnoreCase("M")) { return value * MB; } else if (units.equalsIgnoreCase("G")) { return value * GB; } else if (units.equalsIgnoreCase("T")) { return value * TB; } else { log.error("Unable to recognize units: " + string); return DEFAULT_MAX_SIZE; } } catch (ParseException e) { log.error("Unable to parse: " + string, e); return DEFAULT_MAX_SIZE; } } log.error("Unable to parse bytes: " + string); return DEFAULT_MAX_SIZE; }
From source file:org.projectforge.common.NumberHelper.java
public static NumberFormat getNumberFraction2Format(final Locale locale) { final NumberFormat format = NumberFormat.getNumberInstance(locale); format.setMaximumFractionDigits(2);/*w ww.ja va 2 s .c om*/ format.setMinimumFractionDigits(2); return format; }