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

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

源代码1 项目: hop   文件: ActionZipFile.java
private int determineDepth( String depthString ) throws HopException {
  DecimalFormat df = new DecimalFormat( "0" );
  ParsePosition pp = new ParsePosition( 0 );
  df.setParseIntegerOnly( true );
  try {
    Number n = df.parse( depthString, pp );
    if ( n == null ) {
      return 1; // default
    }
    if ( pp.getErrorIndex() == 0 ) {
      throw new HopException( "Unable to convert stored depth '"
        + depthString + "' to depth at position " + pp.getErrorIndex() );
    }
    return n.intValue();
  } catch ( Exception e ) {
    throw new HopException( "Unable to convert stored depth '" + depthString + "' to depth", e );
  }
}
 
private NumberFormat getInstance(Locale locale,
                                        int choice) {
    if (locale == null) {
        throw new NullPointerException();
    }

    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    String[] numberPatterns = adapter.getLocaleResources(locale).getNumberPatterns();
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
    int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
    DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);

    if (choice == INTEGERSTYLE) {
        format.setMaximumFractionDigits(0);
        format.setDecimalSeparatorAlwaysShown(false);
        format.setParseIntegerOnly(true);
    } else if (choice == CURRENCYSTYLE) {
        adjustForCurrencyDefaultFractionDigits(format, symbols);
    }

    return format;
}
 
源代码3 项目: jdk8u60   文件: NumberFormatProviderImpl.java
private NumberFormat getInstance(Locale locale,
                                        int choice) {
    if (locale == null) {
        throw new NullPointerException();
    }

    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    String[] numberPatterns = adapter.getLocaleResources(locale).getNumberPatterns();
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
    int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
    DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);

    if (choice == INTEGERSTYLE) {
        format.setMaximumFractionDigits(0);
        format.setDecimalSeparatorAlwaysShown(false);
        format.setParseIntegerOnly(true);
    } else if (choice == CURRENCYSTYLE) {
        adjustForCurrencyDefaultFractionDigits(format, symbols);
    }

    return format;
}
 
源代码4 项目: openjdk-jdk8u   文件: NumberFormatProviderImpl.java
private NumberFormat getInstance(Locale locale,
                                        int choice) {
    if (locale == null) {
        throw new NullPointerException();
    }

    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    String[] numberPatterns = adapter.getLocaleResources(locale).getNumberPatterns();
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
    int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
    DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);

    if (choice == INTEGERSTYLE) {
        format.setMaximumFractionDigits(0);
        format.setDecimalSeparatorAlwaysShown(false);
        format.setParseIntegerOnly(true);
    } else if (choice == CURRENCYSTYLE) {
        adjustForCurrencyDefaultFractionDigits(format, symbols);
    }

    return format;
}
 
源代码5 项目: pentaho-kettle   文件: JobEntryZipFile.java
private int determineDepth( String depthString ) throws KettleException {
  DecimalFormat df = new DecimalFormat( "0" );
  ParsePosition pp = new ParsePosition( 0 );
  df.setParseIntegerOnly( true );
  try {
    Number n = df.parse( depthString, pp );
    if ( n == null ) {
      return 1; // default
    }
    if ( pp.getErrorIndex() == 0 ) {
      throw new KettleException( "Unable to convert stored depth '"
        + depthString + "' to depth at position " + pp.getErrorIndex() );
    }
    return n.intValue();
  } catch ( Exception e ) {
    throw new KettleException( "Unable to convert stored depth '" + depthString + "' to depth", e );
  }
}
 
源代码6 项目: openjdk-jdk9   文件: NumberFormatProviderImpl.java
private NumberFormat getInstance(Locale locale,
                                        int choice) {
    if (locale == null) {
        throw new NullPointerException();
    }

    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    String[] numberPatterns = adapter.getLocaleResources(locale).getNumberPatterns();
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
    int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
    DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);

    if (choice == INTEGERSTYLE) {
        format.setMaximumFractionDigits(0);
        format.setDecimalSeparatorAlwaysShown(false);
        format.setParseIntegerOnly(true);
    } else if (choice == CURRENCYSTYLE) {
        adjustForCurrencyDefaultFractionDigits(format, symbols);
    }

    return format;
}
 
源代码7 项目: jdk8u-jdk   文件: NumberFormatProviderImpl.java
private NumberFormat getInstance(Locale locale,
                                        int choice) {
    if (locale == null) {
        throw new NullPointerException();
    }

    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    String[] numberPatterns = adapter.getLocaleResources(locale).getNumberPatterns();
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
    int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
    DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);

    if (choice == INTEGERSTYLE) {
        format.setMaximumFractionDigits(0);
        format.setDecimalSeparatorAlwaysShown(false);
        format.setParseIntegerOnly(true);
    } else if (choice == CURRENCYSTYLE) {
        adjustForCurrencyDefaultFractionDigits(format, symbols);
    }

    return format;
}
 
private NumberFormat getInstance(Locale locale,
                                        int choice) {
    if (locale == null) {
        throw new NullPointerException();
    }

    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    String[] numberPatterns = adapter.getLocaleResources(locale).getNumberPatterns();
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
    int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
    DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);

    if (choice == INTEGERSTYLE) {
        format.setMaximumFractionDigits(0);
        format.setDecimalSeparatorAlwaysShown(false);
        format.setParseIntegerOnly(true);
    } else if (choice == CURRENCYSTYLE) {
        adjustForCurrencyDefaultFractionDigits(format, symbols);
    }

    return format;
}
 
源代码9 项目: openjdk-8   文件: NumberFormatProviderImpl.java
private NumberFormat getInstance(Locale locale,
                                        int choice) {
    if (locale == null) {
        throw new NullPointerException();
    }

    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    String[] numberPatterns = adapter.getLocaleResources(locale).getNumberPatterns();
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
    int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
    DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);

    if (choice == INTEGERSTYLE) {
        format.setMaximumFractionDigits(0);
        format.setDecimalSeparatorAlwaysShown(false);
        format.setParseIntegerOnly(true);
    } else if (choice == CURRENCYSTYLE) {
        adjustForCurrencyDefaultFractionDigits(format, symbols);
    }

    return format;
}
 
源代码10 项目: jdk8u-jdk   文件: NumberFormatProviderImpl.java
private NumberFormat getInstance(Locale locale,
                                        int choice) {
    if (locale == null) {
        throw new NullPointerException();
    }

    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    String[] numberPatterns = adapter.getLocaleResources(locale).getNumberPatterns();
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
    int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
    DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);

    if (choice == INTEGERSTYLE) {
        format.setMaximumFractionDigits(0);
        format.setDecimalSeparatorAlwaysShown(false);
        format.setParseIntegerOnly(true);
    } else if (choice == CURRENCYSTYLE) {
        adjustForCurrencyDefaultFractionDigits(format, symbols);
    }

    return format;
}
 
源代码11 项目: jdk8u-dev-jdk   文件: NumberFormatProviderImpl.java
private NumberFormat getInstance(Locale locale,
                                        int choice) {
    if (locale == null) {
        throw new NullPointerException();
    }

    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    String[] numberPatterns = adapter.getLocaleResources(locale).getNumberPatterns();
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
    int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
    DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);

    if (choice == INTEGERSTYLE) {
        format.setMaximumFractionDigits(0);
        format.setDecimalSeparatorAlwaysShown(false);
        format.setParseIntegerOnly(true);
    } else if (choice == CURRENCYSTYLE) {
        adjustForCurrencyDefaultFractionDigits(format, symbols);
    }

    return format;
}
 
源代码12 项目: snap-desktop   文件: RangeEditorDialog.java
DoubleFormatter(String pattern) {
    final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.ENGLISH);
    format = new DecimalFormat(pattern, decimalFormatSymbols);

    format.setParseIntegerOnly(false);
    format.setParseBigDecimal(false);
    format.setDecimalSeparatorAlwaysShown(true);
}
 
源代码13 项目: easyexcel   文件: DataFormatter.java
/**
 * @return a <tt>DecimalFormat</tt> with parseIntegerOnly set <code>true</code>
 */
private static DecimalFormat createIntegerOnlyFormat(String fmt) {
    DecimalFormatSymbols dsf = DecimalFormatSymbols.getInstance(Locale.ROOT);
    DecimalFormat result = new DecimalFormat(fmt, dsf);
    result.setParseIntegerOnly(true);
    return result;
}
 
源代码14 项目: easyexcel   文件: DataFormatter1.java
/**
 * @return a <tt>DecimalFormat</tt> with parseIntegerOnly set <code>true</code>
 */
private static DecimalFormat createIntegerOnlyFormat(String fmt) {
    DecimalFormatSymbols dsf = DecimalFormatSymbols.getInstance(Locale.ROOT);
    DecimalFormat result = new DecimalFormat(fmt, dsf);
    result.setParseIntegerOnly(true);
    return result;
}
 
源代码15 项目: lams   文件: DataFormatter.java
/**
 * @return a <tt>DecimalFormat</tt> with parseIntegerOnly set <code>true</code>
 */
private static DecimalFormat createIntegerOnlyFormat(String fmt) {
    DecimalFormatSymbols dsf = DecimalFormatSymbols.getInstance(Locale.ROOT);
    DecimalFormat result = new DecimalFormat(fmt, dsf);
    result.setParseIntegerOnly(true);
    return result;
}
 
源代码16 项目: Bytecoder   文件: TNumberFormat.java
public static NumberFormat getIntegerInstance(final Locale aLocale) {
    final ResourceBundle bundle = ResourceBundle.getBundle("localedata", aLocale);
    final DecimalFormatSymbols theSymbols = DecimalFormatSymbols.getInstance(aLocale);
    final DecimalFormat theFormat = new DecimalFormat(bundle.getString("numberformat.integer"), theSymbols);
    theFormat.setParseIntegerOnly(true);
    return theFormat;
}
 
源代码17 项目: j2objc   文件: DecimalFormatTest.java
public void test_parse_integerOnly() throws Exception {
    DecimalFormat format = new DecimalFormat();
    assertFalse("Default value of isParseIntegerOnly is true", format.isParseIntegerOnly());

    format.setParseIntegerOnly(true);
    assertTrue(format.isParseIntegerOnly());
    Number result = format.parse("123.123");
    assertEquals(new Long("123"), result);

    format.setParseIntegerOnly(false);
    assertFalse(format.isParseIntegerOnly());
    result = format.parse("123.123");
    assertEquals(new Double("123.123"), result);
}
 
源代码18 项目: Bytecoder   文件: NumberFormatProviderImpl.java
private NumberFormat getInstance(Locale locale,
                                        int choice) {
    if (locale == null) {
        throw new NullPointerException();
    }

    // Check for region override
    Locale override = locale.getUnicodeLocaleType("nu") == null ?
        CalendarDataUtility.findRegionOverride(locale) :
        locale;

    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    String[] numberPatterns = adapter.getLocaleResources(override).getNumberPatterns();
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(override);
    int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
    if (choice == CURRENCYSTYLE &&
        numberPatterns.length > ACCOUNTINGSTYLE &&
        !numberPatterns[ACCOUNTINGSTYLE].isEmpty() &&
        "account".equalsIgnoreCase(override.getUnicodeLocaleType("cf"))) {
        entry = ACCOUNTINGSTYLE;
    }
    DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);

    if (choice == INTEGERSTYLE) {
        format.setMaximumFractionDigits(0);
        format.setDecimalSeparatorAlwaysShown(false);
        format.setParseIntegerOnly(true);
    } else if (choice == CURRENCYSTYLE) {
        adjustForCurrencyDefaultFractionDigits(format, symbols);
    }

    return format;
}
 
源代码19 项目: 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);
}
 
源代码20 项目: snap-desktop   文件: RegionBoundsInputUI.java
DoubleFormatter(String pattern) {
    final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.ENGLISH);
    format = new DecimalFormat(pattern, decimalFormatSymbols);

    format.setParseIntegerOnly(false);
    format.setParseBigDecimal(false);
    format.setDecimalSeparatorAlwaysShown(true);
}