/** * Returns the {@link NumberFormat} used for the <tt>c</tt> built-in. This is always US English * <code>"0.################"</code>, without grouping and without superfluous decimal separator. */ public NumberFormat getCNumberFormat() { // It can't be cached in a static field, because DecimalFormat-s aren't // thread-safe. if (cNumberFormat == null) { cNumberFormat = (DecimalFormat) C_NUMBER_FORMAT.clone(); } return cNumberFormat; }
/** * Use this accessor to access the <tt>DECIMAL_FORMAT</tt> constant. * * @return A clone of DECIMAL_FORMAT. */ private static DecimalFormat getDecimalFormat() { return (DecimalFormat) DECIMAL_FORMAT.clone(); }
/** * Returns the {@link NumberFormat} used for the <tt>c</tt> built-in. This is always US English * <code>"0.################"</code>, without grouping and without superfluous decimal separator. */ public NumberFormat getCNumberFormat() { // It can't be cached in a static field, because DecimalFormat-s aren't // thread-safe. if (cNumberFormat == null) { cNumberFormat = (DecimalFormat) C_NUMBER_FORMAT.clone(); } return cNumberFormat; }
/** * Returns the {@link NumberFormat} used for the <tt>c</tt> built-in. This is always US English * <code>"0.################"</code>, without grouping and without superfluous decimal separator. */ public NumberFormat getCNumberFormat() { // It can't be cached in a static field, because DecimalFormat-s aren't // thread-safe. if (cNumberFormat == null) { cNumberFormat = (DecimalFormat) C_NUMBER_FORMAT.clone(); } return cNumberFormat; }
/** * Returns the {@link NumberFormat} used for the <tt>c</tt> built-in. * This is always US English <code>"0.################"</code>, without * grouping and without superfluous decimal separator. */ public NumberFormat getCNumberFormat() { // It can't be cached in a static field, because DecimalFormat-s aren't // thread-safe. if (cNumberFormat == null) { cNumberFormat = (DecimalFormat) C_NUMBER_FORMAT.clone(); } return cNumberFormat; }
/** * @return The {@link DecimalFormat} object that formats an object like the * {@link #getCurrencyFormat()} but without the currency sign. Always * returns a copy of the contained formatter for thread-safety and * modification. */ @Nonnull public DecimalFormat getValueFormat () { // DecimalFormat is not thread safe - clone! return (DecimalFormat) this.m_aValueFormat.clone (); }
/** * @return The {@link DecimalFormat} used to format this currency. Always * returns a copy of the contained formatter for thread-safety and * modification. */ @Nonnull public DecimalFormat getCurrencyFormat () { // DecimalFormat is not thread safe - clone! return (DecimalFormat) this.m_aCurrencyFormat.clone (); }
protected static String convertToString(final Double input) { if (input == null) return null; // DecimalFormat is not thread-safe; it's better to clone it here return ((DecimalFormat) (FORMAT.clone())).format(input) + UNIT; }
@SuppressWarnings("unchecked") @Override public Object clone() { try { NumberFormatBasedConverter<S, T> copy = (NumberFormatBasedConverter<S, T>) super.clone(); copy.format = (DecimalFormat) format.clone(); return copy; } catch (CloneNotSupportedException e) { throw new RuntimeException(e); } }
/** * This was deemed to be more Java like, however performs 10x slower than * format2() -- which unfortunately rounds too early. * @param f value * @param digits digits to include in format * @return formatted value. */ public static String format(double f, int digits) { if (digits >= formatters.length) { return "" + f; } //Clone the formatter so that it's thread-safe // TODO: well, we would do this clone for every time this method is called. // to make such things MT-safe and prevent too much impact on performance, we should do a // more thorough implementation review of such static variables. DecimalFormat df = (DecimalFormat) formatters[digits].clone(); return df.format(f); }
/** * Clones the formatter. * * @return the clone. * @throws CloneNotSupportedException if cloning failed. */ public Object clone() { try { final FastDecimalFormat format = (FastDecimalFormat) super.clone(); format.decimalFormat = (DecimalFormat) decimalFormat.clone(); return format; } catch ( CloneNotSupportedException e ) { throw new IllegalStateException(); } } }
public java.text.DecimalFormat copy(){ return (java.text.DecimalFormat) DECIMAL_FORMAT.get().clone(); } }
@Override public Object clone() { DecimalFormatICU other = (DecimalFormatICU)super.clone(); other.fIcuDecfmt = (DecimalFormat)fIcuDecfmt.clone(); return other; }
@Override public DecimalFormat getFormat() { return (DecimalFormat) getFormatInternal().clone(); }
/** * Creates a {@link BigDecimalPM.Format} using the given two formats. * * @param aStrictFormat the strict format defines, how to format a * BigDecimal into a String and how to parse it * @param aSimplifiedFormat the simplified format defines, how to parse * a String if the strict format fails to parse it */ public Format(DecimalFormat aStrictFormat, DecimalFormat aSimplifiedFormat) { strictFormat = (DecimalFormat)aStrictFormat.clone(); strictFormat.setParseBigDecimal(true); simplifiedFormat = (DecimalFormat)aSimplifiedFormat.clone(); simplifiedFormat.setParseBigDecimal(true); }
@Override public <T> String render(final Class<? extends T> dataType, final T data, final String... optionalFormatPattern) { assert dataType != null; if ((optionalFormatPattern == null) || (optionalFormatPattern.length == 0) || (optionalFormatPattern[0] == null)) { return data == null ? null : data.toString(); } if (Date.class.isAssignableFrom(dataType)) { SimpleDateFormat dateFormat = new SimpleDateFormat(optionalFormatPattern[0], DateFormatSymbols.getInstance(locale)); dateFormat.setTimeZone(timezone); return dateFormat.format(data); } if (isNumber(dataType)) { DecimalFormat clone = (DecimalFormat) decimalFormat.clone(); clone.applyPattern(optionalFormatPattern[0]); return clone.format(data); } throw new IllegalArgumentException("Type " + data.getClass().getSimpleName() + " can not be formatted using a pattern"); }
/** * Creates a {@link BigDecimalPM.Format} using the given * {@link DecimalFormat}. * * @param format */ public Format(DecimalFormat format) { strictFormat = (DecimalFormat)format.clone(); strictFormat.setParseBigDecimal(true); simplifiedFormat = createSimplifiedNumberFormat(strictFormat); }
/*** * Create a new converter * * @param dateFormat format of the dates in the Excel. This format is cloned in the constructor to avoid inferences. * @param decimalFormat format of the decimals in the Excel. This format is cloned in the constructor to avoid inferences. * @param dateTimeFormat format of date time cells in the Excel. This format is cloned in the constructor to avoid inferences. */ public ExcelConverterSimpleSpreadSheetCellDAO(SimpleDateFormat dateFormat, DecimalFormat decimalFormat, SimpleDateFormat dateTimeFormat) { this.schemaRow = new ArrayList<>(); this.dateFormat = (SimpleDateFormat) dateFormat.clone(); this.decimalFormat = (DecimalFormat) decimalFormat.clone(); this.decimalFormat.setParseBigDecimal(true); if (dateTimeFormat!=null) { this.dateTimeFormat = (SimpleDateFormat) dateTimeFormat.clone(); } }
@Override public void setFormat(DecimalFormat format) { Assertions.assertNotNull(format); DecimalFormat newFormat = (DecimalFormat) format.clone(); newFormat.setParseBigDecimal(true); propertySupport.setProperty(INumberValueContainer.PROP_DECIMAL_FORMAT, newFormat); updateDisplayTexts(); }
@Override public void setFormat(DecimalFormat format) { Assertions.assertNotNull(format); try { DecimalFormat newFormat = (DecimalFormat) format.clone(); newFormat.setParseBigDecimal(true); propertySupport.setProperty(INumberValueContainer.PROP_DECIMAL_FORMAT, newFormat); refreshDisplayText(); } finally { setFieldChanging(false); } }