java.text.DecimalFormat#setParseBigDecimal ( )源码实例Demo

下面列出了java.text.DecimalFormat#setParseBigDecimal ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Open-Lowcode   文件: CDecimalFormatter.java
/**
 * creates a decimal formatter from the server message
 * 
 * @param reader reader of the message coming from the server
 * @throws OLcRemoteException if anything bad happens on the server
 * @throws IOException        if a problem happens during the message
 *                            transmission
 */
public CDecimalFormatter(MessageReader reader) throws OLcRemoteException, IOException {
	reader.returnNextStartStructure("DEF");
	minimum = reader.returnNextDecimalField("MIN");
	maximum = reader.returnNextDecimalField("MAX");
	linear = reader.returnNextBooleanField("LIN");
	colorscheme = reader.returnNextBooleanField("CLS");
	reader.returnNextEndStructure("DEF");
	String formatfordecimalstring = "###,###.###";
	formatfordecimal = new DecimalFormat(formatfordecimalstring);
	DecimalFormatSymbols formatforsymbol = formatfordecimal.getDecimalFormatSymbols();
	formatforsymbol.setGroupingSeparator(' ');
	formatforsymbol.setDecimalSeparator('.');
	formatfordecimal.setDecimalFormatSymbols(formatforsymbol);
	formatfordecimal.setParseBigDecimal(true);
}
 
@Override
protected NumberFormat getNumberFormat(Locale locale) {
	DecimalFormat format = (DecimalFormat) NumberFormat.getCurrencyInstance(locale);
	format.setParseBigDecimal(true);
	format.setMaximumFractionDigits(this.fractionDigits);
	format.setMinimumFractionDigits(this.fractionDigits);
	if (this.roundingMode != null) {
		format.setRoundingMode(this.roundingMode);
	}
	if (this.currency != null) {
		format.setCurrency(this.currency);
	}
	if (this.pattern != null) {
		format.applyPattern(this.pattern);
	}
	return format;
}
 
@Override
public NumberFormat getNumberFormat(Locale locale) {
	NumberFormat format = NumberFormat.getInstance(locale);
	if (!(format instanceof DecimalFormat)) {
		if (this.pattern != null) {
			throw new IllegalStateException("Cannot support pattern for non-DecimalFormat: " + format);
		}
		return format;
	}
	DecimalFormat decimalFormat = (DecimalFormat) format;
	decimalFormat.setParseBigDecimal(true);
	if (this.pattern != null) {
		decimalFormat.applyPattern(this.pattern);
	}
	return decimalFormat;
}
 
源代码4 项目: j2objc   文件: DecimalFormatTest.java
public void test_parse_bigDecimal() throws Exception {
    // parseBigDecimal default to false
    DecimalFormat form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
    assertFalse(form.isParseBigDecimal());
    form.setParseBigDecimal(true);
    assertTrue(form.isParseBigDecimal());

    Number result = form.parse("123.123");
    assertEquals(new BigDecimal("123.123"), result);

    form.setParseBigDecimal(false);
    assertFalse(form.isParseBigDecimal());

    result = form.parse("123.123");
    assertFalse(result instanceof BigDecimal);
}
 
@Override
protected NumberFormat getNumberFormat(Locale locale) {
	DecimalFormat format = (DecimalFormat) NumberFormat.getCurrencyInstance(locale);
	format.setParseBigDecimal(true);
	format.setMaximumFractionDigits(this.fractionDigits);
	format.setMinimumFractionDigits(this.fractionDigits);
	if (this.roundingMode != null) {
		format.setRoundingMode(this.roundingMode);
	}
	if (this.currency != null) {
		format.setCurrency(this.currency);
	}
	if (this.pattern != null) {
		format.applyPattern(this.pattern);
	}
	return format;
}
 
源代码6 项目: nano-wallet-android   文件: NanoWallet.java
/**
 * Return the currency formatted local currency amount as a string
 *
 * @return Formatted local currency amount
 */
public String getSendLocalCurrencyAmountFormatted() {
    if (sendLocalCurrencyAmount.length() > 0) {
        try {
            DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(getLocalCurrency().getLocale());
            df.setParseBigDecimal(true);
            BigDecimal bd = (BigDecimal) df.parseObject(sanitize(sendLocalCurrencyAmount));
            return currencyFormat(bd);
        } catch (ParseException e) {
            ExceptionHandler.handle(e);
        }
        return "";
    } else {
        return "";
    }
}
 
源代码7 项目: lams   文件: CurrencyStyleFormatter.java
@Override
protected NumberFormat getNumberFormat(Locale locale) {
	DecimalFormat format = (DecimalFormat) NumberFormat.getCurrencyInstance(locale);
	format.setParseBigDecimal(true);
	format.setMaximumFractionDigits(this.fractionDigits);
	format.setMinimumFractionDigits(this.fractionDigits);
	if (this.roundingMode != null) {
		format.setRoundingMode(this.roundingMode);
	}
	if (this.currency != null) {
		format.setCurrency(this.currency);
	}
	if (this.pattern != null) {
		format.applyPattern(this.pattern);
	}
	return format;
}
 
源代码8 项目: pentaho-metadata   文件: DataFormatter.java
/**
 * 
 * @param datatype
 *          should be one from {@link DataType}
 * @param mask
 * @param data
 * @return {@link String} - data which was formatted by mask or data if we have not correct mask
 */
public static String getFormatedString( DataType dataType, String mask, Object data ) {
  try {
    switch ( dataType ) {
      case NUMERIC:
        DecimalFormat decimalFormat = new DecimalFormat( mask );
        decimalFormat.setParseBigDecimal( true );
        return decimalFormat.format( data  );
      case DATE:
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat( mask );
        if ( data instanceof Date ) {
          return simpleDateFormat.format( data );
        }
        Date dateFromstring = DateDetector.getDateFromString( String.valueOf( data  ) );
        return simpleDateFormat.format( dateFromstring );
      case STRING:
      case UNKNOWN:
      case BOOLEAN:
      case BINARY:
      case IMAGE:
      case URL:
      default:
        return String.valueOf( data );
    }
  } catch ( Exception e ) {
    log.debug( DataFormatter.class.getName() + " could not apply mask to data. The original data was returned" ); //$NON-NLS-1$  //$NON-NLS-2$
    return String.valueOf( data );
  }
}
 
/**
 * Sets up the formatter for the test using Combinations
 */
@Before
public void setUp() {
    DecimalFormat df1 = new DecimalFormat("#,##0.0##");
    this.formatter = new NumberFormatWrapper<>(df1, Integer.class);
    this.lenientFormatter = new NumberFormatWrapper<>(df1, Integer.class, true);
    
    DecimalFormat df2 = new DecimalFormat("#,##0.0##");
    df2.setParseBigDecimal(true);
    this.parseBigDecimalFormatter = new NumberFormatWrapper<>(df2, Integer.class);
    this.lenientParseBigDecimalFormatter = new NumberFormatWrapper<>(df2, Integer.class, true);
}
 
源代码10 项目: Open-Lowcode   文件: StandardUtil.java
/**
 * Open Lowcode uses as default a number formatting that is non ambiguous for
 * both English speaking and French speaking countries. Decimal separator is dot
 * '.', thousands grouping separator is space ' '.
 * 
 * @return
 */
public static DecimalFormat getOLcDecimalFormatter() {
	String formatfordecimalstring = "###,###.###";
	DecimalFormat formatfordecimal = new DecimalFormat(formatfordecimalstring);
	DecimalFormatSymbols formatforsymbol = formatfordecimal.getDecimalFormatSymbols();
	formatforsymbol.setGroupingSeparator(' ');
	formatforsymbol.setDecimalSeparator('.');
	formatfordecimal.setDecimalFormatSymbols(formatforsymbol);
	formatfordecimal.setParseBigDecimal(true);
	return formatfordecimal;
}
 
/**
 * 数値のフォーマッタを作成する。
 * <p>アノテーション{@link CsvNumberFormat}の値を元に作成します。</p>
 * @param field フィールド情報
 * @param config システム設定
 * @return アノテーション{@link CsvNumberFormat}が付与されていない場合は、空を返す。
 */
@SuppressWarnings("unchecked")
protected Optional<NumberFormatWrapper<N>> createFormatter(final FieldAccessor field, final Configuration config) {
    
    final Optional<CsvNumberFormat> formatAnno = field.getAnnotation(CsvNumberFormat.class);
    
    if(!formatAnno.isPresent()) {
        return Optional.empty();
    }
    
    final String pattern = formatAnno.get().pattern();
    if(pattern.isEmpty()) {
        return Optional.empty();
    }
    
    final boolean lenient = formatAnno.get().lenient();
    final Locale locale = Utils.getLocale(formatAnno.get().locale());
    final Optional<Currency> currency = formatAnno.get().currency().isEmpty() ? Optional.empty()
            : Optional.of(Currency.getInstance(formatAnno.get().currency()));
    final RoundingMode roundingMode = formatAnno.get().rounding();
    final DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
    
    final DecimalFormat formatter = new DecimalFormat(pattern, symbols);
    formatter.setParseBigDecimal(true);
    formatter.setRoundingMode(roundingMode);
    currency.ifPresent(c -> formatter.setCurrency(c));
    
    final NumberFormatWrapper<N> wrapper = new NumberFormatWrapper<>(formatter, (Class<N>)field.getType(), lenient);
    wrapper.setValidationMessage(formatAnno.get().message());
    
    return Optional.of(wrapper);
    
}
 
源代码12 项目: snap-desktop   文件: DecimalFormatter.java
public DecimalFormatter(String pattern) {
    final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.ENGLISH);
    format = new DecimalFormat(pattern, decimalFormatSymbols);
    format.setParseIntegerOnly(false);
    format.setParseBigDecimal(false);
    format.setDecimalSeparatorAlwaysShown(true);
}
 
源代码13 项目: ph-commons   文件: LocaleParser.java
@Nullable
public static BigDecimal parseBigDecimal (@Nullable final String sStr,
                                          @Nonnull final DecimalFormat aNF,
                                          @Nullable final BigDecimal aDefault)
{
  ValueEnforcer.notNull (aNF, "NumberFormat");

  aNF.setParseBigDecimal (true);
  return (BigDecimal) parse (sStr, aNF, aDefault);
}
 
源代码14 项目: pushfish-android   文件: LocaleSafeDecimalFormat.java
/**
 * Regardless of the default locale, comma ('.') is used as decimal separator
 *
 * @param source
 * @return
 * @throws ParseException
 */
public BigDecimal parse(String source) throws ParseException {
    DecimalFormatSymbols symbols = new DecimalFormatSymbols();
    symbols.setDecimalSeparator('.');
    DecimalFormat format = new DecimalFormat("#.#", symbols);
    format.setParseBigDecimal(true);
    return (BigDecimal) format.parse(source);
}
 
源代码15 项目: easyexcel   文件: NumberUtils.java
/**
 * parse
 *
 * @param string
 * @param contentProperty
 * @return
 * @throws ParseException
 */
private static Number parse(String string, ExcelContentProperty contentProperty) throws ParseException {
    String format = contentProperty.getNumberFormatProperty().getFormat();
    RoundingMode roundingMode = contentProperty.getNumberFormatProperty().getRoundingMode();
    DecimalFormat decimalFormat = new DecimalFormat(format);
    decimalFormat.setRoundingMode(roundingMode);
    decimalFormat.setParseBigDecimal(true);
    return decimalFormat.parse(string);
}
 
源代码16 项目: conf4j   文件: BigDecimalConverter.java
@Override
protected Number parseWithFormat(String value, String format, String locale, Type type) {
    DecimalFormat formatter = getFormatter(format, locale);
    formatter.setParseBigDecimal(true);

    try {
        return formatter.parse(value);
    } catch (ParseException e) {
        throw new IllegalArgumentException(format("Unable to convert to BigDecimal. " +
                "The value doesn't match specified format: %s", format), e);
    }
}
 
源代码17 项目: jspoon   文件: HtmlField.java
private BigDecimal getBigDecimal(String value) {
    try {
        DecimalFormat decimalFormat = (spec.getFormat() == null)
                ? (DecimalFormat) DecimalFormat.getInstance(spec.getLocale())
                        : new DecimalFormat(spec.getFormat());

        decimalFormat.setParseBigDecimal(true);
        return (BigDecimal) decimalFormat.parse(value);
    }
    catch (ParseException e) {
        throw new BigDecimalParseException(value, spec.getFormat(), spec.getLocale());
    }

}
 
源代码18 项目: poiji   文件: BigDecimalParser.java
private DecimalFormat getDecimalFormatInstance() {
    NumberFormat numberFormat = NumberFormat.getInstance();
    DecimalFormat decimalFormat = (DecimalFormat) numberFormat;
    decimalFormat.setParseBigDecimal(true);
    return decimalFormat;
}
 
源代码19 项目: pentaho-reporting   文件: DecimalFormatParser.java
/**
 * Sets the format for the filter. If the given format is no Decimal format, a ClassCastException is thrown
 *
 * @param format
 *          The format.
 * @throws NullPointerException
 *           if the given format is null
 * @throws ClassCastException
 *           if the format is no decimal format
 */
public void setFormatter( final Format format ) {
  if ( format == null ) {
    throw new NullPointerException( "The number format given must not be null." );
  }
  final DecimalFormat dfmt = (DecimalFormat) format;
  dfmt.setParseBigDecimal( true );
  super.setFormatter( dfmt );
}
 
源代码20 项目: SaneEconomy   文件: NumberUtils.java
private static DecimalFormat constructDecimalFormat() {
    DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getInstance();

    decimalFormat.setParseBigDecimal(true);

    return decimalFormat;
}