Package com.ibm.icu.text

Examples of com.ibm.icu.text.NumberFormat


    /*
     * Test method for 'com.ibm.icu.x.text.NumberFormat.setMinimumFractionDigits(int)'
     */
    public void testSetMinimumFractionDigits() {
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMinimumFractionDigits(4);
        assertEquals("1.2000", nf.format(1.2));
    }
View Full Code Here


    /*
     * Test method for 'com.ibm.icu.x.text.NumberFormat.hashCode()'
     */
    public void testHashCode() {
        NumberFormat nf = NumberFormat.getInstance();
        NumberFormat eq = NumberFormat.getInstance(Locale.US);
        NumberFormat neq = NumberFormat.getInstance(Locale.GERMANY);
               
        ICUTestCase.testEHCS(nf, eq, neq);
    }
View Full Code Here

     * Test method for 'com.ibm.icu.text.MessageFormat.getFormats()'
     */
    public void testGetFormats() {
        MessageFormat mf = new MessageFormat(pattern, Locale.US);
        Format[] formats = mf.getFormats();
        NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
        assertEquals(formats[0], nf);
        DateFormat tf = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US);
        assertEquals(formats[1], tf);
        DateFormat df = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.US);
        assertEquals(formats[2], df);
View Full Code Here

   * hour is set to fields[1], minute is set to fields[2] and second is
   * set to fields[3].
   * @return Returns true when the given custom id is valid.
   */
  static boolean parseCustomID(String id, int[] fields) {
    NumberFormat numberFormat = null;

    if (id != null && id.length() > kGMT_ID.length() && id.toUpperCase(Locale.ENGLISH).startsWith(kGMT_ID)) {
      ParsePosition pos = new ParsePosition(kGMT_ID.length());
      int sign = 1;
      int hour = 0;
      int min = 0;
      int sec = 0;

      if (id.charAt(pos.getIndex()) == 0x002D /*'-'*/) {
        sign = -1;
      } else if (id.charAt(pos.getIndex()) != 0x002B /*'+'*/) {
        return false;
      }
      pos.setIndex(pos.getIndex() + 1);

      numberFormat = NumberFormat.getInstance();
      numberFormat.setParseIntegerOnly(true);

      // Look for either hh:mm, hhmm, or hh
      int start = pos.getIndex();

      Number n = numberFormat.parse(id, pos);
      if (pos.getIndex() == start) {
        return false;
      }
      hour = n.intValue();

      if (pos.getIndex() < id.length()) {
        if (pos.getIndex() - start > 2 || id.charAt(pos.getIndex()) != 0x003A /*':'*/) {
          return false;
        }
        // hh:mm
        pos.setIndex(pos.getIndex() + 1);
        int oldPos = pos.getIndex();
        n = numberFormat.parse(id, pos);
        if ((pos.getIndex() - oldPos) != 2) {
          // must be 2 digits
          return false;
        }
        min = n.intValue();
        if (pos.getIndex() < id.length()) {
          if (id.charAt(pos.getIndex()) != 0x003A /*':'*/) {
            return false;
          }
          // [:ss]
          pos.setIndex(pos.getIndex() + 1);
          oldPos = pos.getIndex();
          n = numberFormat.parse(id, pos);
          if (pos.getIndex() != id.length() || (pos.getIndex() - oldPos) != 2) {
            return false;
          }
          sec = n.intValue();
        }
View Full Code Here

     */
    public NumberFormat getNumberFormat(int style) {
        if (style < 0 || style >= NF_LIMIT) {
            throw new IllegalArgumentException("Illegal number format type");
        }
        NumberFormat result = null;
        if (numberFormats != null) {
            result = numberFormats[style];
        }
        if (result != null) {
            result = (NumberFormat) result.clone(); // clone for safety (later optimize)
        } else {
            result = guessNumberFormat(style);
        }
        return result;
    }
View Full Code Here

     * @param style
     * @draft ICU 3.6
     * @provisional This API might change or be removed in a future release.
     */
    protected NumberFormat guessNumberFormat(int style) {
        NumberFormat result;
        ULocale nfLocale = getAvailableLocale(TYPE_NUMBERFORMAT);
        if (nfLocale == null) {
            nfLocale = ULocale.ROOT;
        }
        switch (style) {
        case NF_NUMBER:
            result = NumberFormat.getInstance(nfLocale);
            break;
        case NF_SCIENTIFIC:
            result = NumberFormat.getScientificInstance(nfLocale);
            break;
        case NF_INTEGER:
            result = NumberFormat.getIntegerInstance(nfLocale);
            break;
        case NF_PERCENT:
            result = NumberFormat.getPercentInstance(nfLocale);
            break;
        case NF_CURRENCY:
            result = NumberFormat.getCurrencyInstance(nfLocale);
            result.setCurrency(getCurrency());
            break;
        default:
            throw new IllegalArgumentException("Unknown number format style");
        }
        return result;
View Full Code Here

     */
    public NumberFormat getNumberFormat(int style) {
        if (style < 0 || style >= NF_LIMIT) {
            throw new IllegalArgumentException("Illegal number format type");
        }
        NumberFormat result = null;
        if (numberFormats != null) {
            result = numberFormats[style];
        }
        if (result != null) {
            result = (NumberFormat) result.clone(); // clone for safety (later optimize)
        } else {
            result = guessNumberFormat(style);
        }
        return result;
    }
View Full Code Here

     * @param style
     * @draft ICU 3.6
     * @provisional This API might change or be removed in a future release.
     */
    protected NumberFormat guessNumberFormat(int style) {
        NumberFormat result;
        ULocale nfLocale = getAvailableLocale(TYPE_NUMBERFORMAT);
        if (nfLocale == null) {
            nfLocale = ULocale.ROOT;
        }
        switch (style) {
        case NF_NUMBER:
            result = NumberFormat.getInstance(nfLocale);
            break;
        case NF_SCIENTIFIC:
            result = NumberFormat.getScientificInstance(nfLocale);
            break;
        case NF_INTEGER:
            result = NumberFormat.getIntegerInstance(nfLocale);
            break;
        case NF_PERCENT:
            result = NumberFormat.getPercentInstance(nfLocale);
            break;
        case NF_CURRENCY:
            result = NumberFormat.getCurrencyInstance(nfLocale);
            result.setCurrency(getCurrency());
            break;
        default:
            throw new IllegalArgumentException("Unknown number format style");
        }
        return result;
View Full Code Here

  private synchronized static Map getConverterMap() {
    // using string-based lookup avoids loading of too many classes
    if (converterMap == null) {
      // NumberFormat to be shared across converters for the formatting of
      // integer values
      NumberFormat integerFormat = NumberFormat.getIntegerInstance();
      // NumberFormat to be shared across converters for formatting non
      // integer values
      NumberFormat numberFormat = NumberFormat.getNumberInstance();

      converterMap = new HashMap();
      // Standard and Boxed Types
      converterMap
          .put(
View Full Code Here

     */
    public NumberFormat getNumberFormat(int style) {
        if (style < 0 || style >= NF_LIMIT) {
            throw new IllegalArgumentException("Illegal number format type");
        }
        NumberFormat result = null;
        if (numberFormats != null) {
            result = numberFormats[style];
        }
        if (result != null) {
            result = (NumberFormat) result.clone(); // clone for safety (later optimize)
        } else {
            result = guessNumberFormat(style);
        }
        return result;
    }
View Full Code Here

TOP

Related Classes of com.ibm.icu.text.NumberFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.