public String formatInteger(final Number target, final Integer minIntegerDigits) { if (target == null) { return null; } try { return NumberUtils.format(target, minIntegerDigits, this.locale); } catch (final Exception e) { throw new TemplateProcessingException( "Error formatting integer with minimum integer digits = " + minIntegerDigits, e); } }
public static String format(final Number target, final Integer minIntegerDigits, final Locale locale) { if (target == null) { return null; } Validate.notNull(minIntegerDigits, "Minimum integer digits cannot be null"); return formatNumber(target, minIntegerDigits, NumberPointType.NONE, Integer.valueOf(0), NumberPointType.NONE, locale); }
/** * <p> * Produces an array with a sequence of integer numbers. * </p> * * @param from value to start the sequence from * @param to value to produce the sequence to * @return the Integer[] sequence * * @since 1.1.2 */ public Integer[] sequence(final Integer from, final Integer to) { return NumberUtils.sequence(from, to); }
format.setDecimalFormatSymbols(computeDecimalFormatSymbols(decimalPointType, thousandsPointType, locale));
public String formatPercent(final Number target, final Integer minIntegerDigits, final Integer decimalDigits) { if (target == null) { return null; } try { return NumberUtils.formatPercent(target, minIntegerDigits, decimalDigits, this.locale); } catch (final Exception e) { throw new TemplateProcessingException("Error formatting percent", e); } }
public String formatCurrency(final Number target) { if (target == null) { return null; } try { return NumberUtils.formatCurrency(target, this.locale); } catch (final Exception e) { throw new TemplateProcessingException("Error formatting currency", e); } }
private static String formatNumber( final Number target, final Integer minIntegerDigits, final NumberPointType thousandsPointType, final Integer fractionDigits, final NumberPointType decimalPointType, final Locale locale) { Validate.notNull(target, "Cannot apply format on null"); Validate.notNull(fractionDigits, "Fraction digits cannot be null"); Validate.notNull(decimalPointType, "Decimal point type cannot be null"); Validate.notNull(thousandsPointType, "Thousands point type cannot be null"); Validate.notNull(locale, "Locale cannot be null"); DecimalFormat format = null; if (target instanceof Double || target instanceof Float || target instanceof BigDecimal || target instanceof Integer || target instanceof Long || target instanceof Byte || target instanceof Short || target instanceof BigInteger) { format = (DecimalFormat) NumberFormat.getNumberInstance(); format.setMinimumFractionDigits(fractionDigits.intValue()); format.setMaximumFractionDigits(fractionDigits.intValue()); if (minIntegerDigits != null) { format.setMinimumIntegerDigits(minIntegerDigits.intValue()); } format.setDecimalSeparatorAlwaysShown(decimalPointType != NumberPointType.NONE && fractionDigits.intValue() > 0); format.setGroupingUsed(thousandsPointType != NumberPointType.NONE); format.setDecimalFormatSymbols(computeDecimalFormatSymbols(decimalPointType, thousandsPointType, locale)); } else { throw new IllegalArgumentException( "Cannot format object of class \"" + target.getClass().getName() + "\" as a decimal number"); } return format.format(target); }
public static String format(final Number target, final Integer minIntegerDigits, final NumberPointType thousandsPointType, final Locale locale) { if (target == null) { return null; } Validate.notNull(minIntegerDigits, "Minimum integer digits cannot be null"); Validate.notNull(thousandsPointType, "Thousands point type cannot be null"); return formatNumber(target, minIntegerDigits, thousandsPointType, Integer.valueOf(0), NumberPointType.NONE, locale); }
public String formatDecimal(final Number target, final Integer minIntegerDigits, final Integer decimalDigits) { if (target == null) { return null; } try { return NumberUtils.format(target, minIntegerDigits, decimalDigits, this.locale); } catch (final Exception e) { throw new TemplateProcessingException( "Error formatting decimal with minimum integer digits = " + minIntegerDigits + " and decimal digits " + decimalDigits, e); } }
/** * <p> * Produces an array with a sequence of integer numbers, using the * specified step. * </p> * * @param from value to start the sequence from * @param to value to produce the sequence to * @param step the step to be used * @return the Integer[] sequence * * @since 2.0.9 */ public Integer[] sequence(final Integer from, final Integer to, final Integer step) { return NumberUtils.sequence(from, to, step); }
public static String format(final Number target, final Integer minIntegerDigits, final Integer decimalDigits, final Locale locale) { if (target == null) { return null; } Validate.notNull(minIntegerDigits, "Minimum integer digits cannot be null"); Validate.notNull(decimalDigits, "Decimal digits cannot be null"); return formatNumber(target, minIntegerDigits, NumberPointType.NONE, decimalDigits, NumberPointType.DEFAULT, locale); }
public String formatDecimal(final Number target, final Integer minIntegerDigits, final Integer decimalDigits, final String decimalPointType) { if (target == null) { return null; } final NumberPointType decimalNumberPointType = NumberPointType.match(decimalPointType); if (decimalNumberPointType == null) { throw new TemplateProcessingException( "Unrecognized point format \"" + decimalPointType + "\""); } try { return NumberUtils.format(target, minIntegerDigits, decimalDigits, decimalNumberPointType, this.locale); } catch (final Exception e) { throw new TemplateProcessingException( "Error formatting decimal with minimum integer digits = " + minIntegerDigits + ", decimal digits = " + decimalDigits + " and decimal point type = " + decimalPointType, e); } }
/** * <p> * Produces an array with a sequence of integer numbers. * </p> * * @param from value to start the sequence from * @param to value to produce the sequence to * @return the Integer[] sequence * * @since 1.1.2 */ public static Integer[] sequence(final Integer from, final Integer to) { return sequence(from, to, Integer.valueOf(from <= to? 1 : -1)); }
public static String format(final Number target, final Integer minIntegerDigits, final Integer decimalDigits, final NumberPointType decimalPointType, final Locale locale) { if (target == null) { return null; } Validate.notNull(minIntegerDigits, "Minimum integer digits cannot be null"); Validate.notNull(decimalDigits, "Decimal digits cannot be null"); Validate.notNull(decimalPointType, "Decimal point type cannot be null"); return formatNumber(target, minIntegerDigits, NumberPointType.NONE, decimalDigits, decimalPointType, locale); }
public String formatInteger(final Number target, final Integer minIntegerDigits, final String thousandsPointType) { if (target == null) { return null; } final NumberPointType thousandsNumberPointType = NumberPointType.match(thousandsPointType); if (thousandsNumberPointType == null) { throw new TemplateProcessingException( "Unrecognized point format \"" + thousandsPointType + "\""); } try { return NumberUtils.format(target, minIntegerDigits, thousandsNumberPointType, this.locale); } catch (final Exception e) { throw new TemplateProcessingException( "Error formatting integer with minimum integer digits = " + minIntegerDigits + " and thousands point type = " + thousandsPointType, e); } }
/** * <p> * Produces an array with a sequence of integer numbers. * </p> * * @param from value to start the sequence from * @param to value to produce the sequence to * @return the Integer[] sequence * * @since 1.1.2 */ public Integer[] sequence(final Integer from, final Integer to) { return NumberUtils.sequence(from, to); }
public static String format(final Number target, final Integer minIntegerDigits, final NumberPointType thousandsPointType, final Integer decimalDigits, final Locale locale) { if (target == null) { return null; } Validate.notNull(minIntegerDigits, "Minimum integer digits cannot be null"); Validate.notNull(thousandsPointType, "Thousands point type cannot be null"); Validate.notNull(decimalDigits, "Decimal digits cannot be null"); return formatNumber(target, minIntegerDigits, thousandsPointType, decimalDigits, NumberPointType.DEFAULT, locale); }
public String formatDecimal(final Number target, final Integer minIntegerDigits, final String thousandsPointType, final Integer decimalDigits, final String decimalPointType) { if (target == null) { return null; } final NumberPointType decimalNumberPointType = NumberPointType.match(decimalPointType); if (decimalNumberPointType == null) { throw new TemplateProcessingException( "Unrecognized point format \"" + decimalPointType + "\""); } final NumberPointType thousandsNumberPointType = NumberPointType.match(thousandsPointType); if (thousandsNumberPointType == null) { throw new TemplateProcessingException( "Unrecognized point format \"" + thousandsPointType + "\""); } try { return NumberUtils.format(target, minIntegerDigits, thousandsNumberPointType, decimalDigits, decimalNumberPointType, this.locale); } catch (final Exception e) { throw new TemplateProcessingException( "Error formatting decimal with minimum integer digits = " + minIntegerDigits + ", thousands point type = " + thousandsPointType + ", decimal digits = " + decimalDigits + " and decimal point type = " + decimalPointType, e); } }
/** * <p> * Produces an array with a sequence of integer numbers, using the * specified step. * </p> * * @param from value to start the sequence from * @param to value to produce the sequence to * @param step the step to be used * @return the Integer[] sequence * * @since 2.0.9 */ public Integer[] sequence(final Integer from, final Integer to, final Integer step) { return NumberUtils.sequence(from, to, step); }
public static String format(final Number target, final Integer minIntegerDigits, final NumberPointType thousandsPointType, final Integer decimalDigits, final NumberPointType decimalPointType, final Locale locale) { if (target == null) { return null; } Validate.notNull(minIntegerDigits, "Minimum integer digits cannot be null"); Validate.notNull(thousandsPointType, "Thousands point type cannot be null"); Validate.notNull(decimalDigits, "Decimal digits cannot be null"); Validate.notNull(decimalPointType, "Decimal point type cannot be null"); return formatNumber(target, minIntegerDigits, thousandsPointType, decimalDigits, decimalPointType, locale); }