Java Code Examples for java.text.DecimalFormat#setParseIntegerOnly()

The following examples show how to use java.text.DecimalFormat#setParseIntegerOnly() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NumberFormatProviderImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: NumberFormatProviderImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: NumberFormatProviderImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: NumberFormatProviderImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 5
Source File: NumberFormatProviderImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 6
Source File: NumberFormatProviderImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 7
Source File: NumberFormatProviderImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 8
Source File: JobEntryZipFile.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
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 );
  }
}
 
Example 9
Source File: NumberFormatProviderImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 10
Source File: NumberFormatProviderImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 11
Source File: ActionZipFile.java    From hop with Apache License 2.0 6 votes vote down vote up
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 );
  }
}
 
Example 12
Source File: DataFormatter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @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;
}
 
Example 13
Source File: TNumberFormat.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: DecimalFormatTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 15
Source File: NumberFormatProviderImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 16
Source File: DataFormatter1.java    From easyexcel with Apache License 2.0 5 votes vote down vote up
/**
 * @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;
}
 
Example 17
Source File: DecimalFormatter.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 18
Source File: DataFormatter.java    From easyexcel with Apache License 2.0 5 votes vote down vote up
/**
 * @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;
}
 
Example 19
Source File: RegionBoundsInputUI.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
DoubleFormatter(String pattern) {
    final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.ENGLISH);
    format = new DecimalFormat(pattern, decimalFormatSymbols);

    format.setParseIntegerOnly(false);
    format.setParseBigDecimal(false);
    format.setDecimalSeparatorAlwaysShown(true);
}
 
Example 20
Source File: RangeEditorDialog.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
DoubleFormatter(String pattern) {
    final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.ENGLISH);
    format = new DecimalFormat(pattern, decimalFormatSymbols);

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