Package com.ibm.icu.text

Examples of com.ibm.icu.text.NumberFormat


    return false;
  }

  @Override public SoyData apply(SoyData value, List<SoyData> args) {
    Locale locale = I18nUtils.parseLocale(localeStringProvider.get());
    NumberFormat instance;
    String formatType = args.isEmpty() ? "decimal" : args.get(0).stringValue();

    if (formatType == "decimal") {
      instance = NumberFormat.getInstance(locale);
    } else if (formatType == "percent") {
      instance = NumberFormat.getPercentInstance(locale);
    } else if (formatType == "currency") {
      instance = NumberFormat.getCurrencyInstance(locale);
    } else if (formatType == "scientific") {
      instance = NumberFormat.getScientificInstance(locale);
    } else {
      throw new IllegalArgumentException(
          String.format("Unrecognized Number Format Type: {0}", formatType));
    }

    return toSoyData(instance.format(((NumberData) value).toFloat()));
  }
View Full Code Here


            int length = finalModel.getStructuredDocument().getLength();
            int regionCount = 0;
            for (int i = 0; i < structuredDocumentRegions.length; i++) {
              regionCount += structuredDocumentRegions[i].getNumberOfRegions();
            }
            NumberFormat formatter = NumberFormat.getIntegerInstance();
            final String regioncount = "Count: " + formatter.format(structuredDocumentRegions.length) + " document regions containing " + formatter.format(regionCount) + " text regions representing " + formatter.format(length) + " characters";//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            display.asyncExec(new Runnable() {
              public void run() {
                if (!counts.isDisposed()) {
                  counts.setText(regioncount);
                  counts.setEnabled(true);
View Full Code Here

   
    return buildDefaultFormat(currency, locale);
  }

  private static MoneyFormat buildDefaultFormat(Currency currency, Locale locale) {
    final NumberFormat nf = NumberFormat.getCurrencyInstance(locale);
    nf.setCurrency(getICUCurrency(currency));
    return new MoneyFormat(nf);
  }
View Full Code Here

            f.format((Object)"Howdy", buf, pos);
        }
        catch (Exception e) {
        }

        NumberFormat nf = f.getNumberFormat();
        f.setNumberFormat(nf);
       
        boolean lenient = f.isLenient();
        f.setLenient(lenient);
       
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

        ULocale[] actualLoc = new ULocale[1];
        if (desiredLocale.equals(ULocale.ROOT)) {
            desiredLocale = ULocale.ROOT;
        }
        NumberFormat fmt = (NumberFormat)service.get(desiredLocale, choice,
                                                     actualLoc);
        if (fmt == null) {
            throw new MissingResourceException("Unable to construct NumberFormat", "", "");
        }
        fmt = (NumberFormat)fmt.clone();

        ULocale uloc = actualLoc[0];
        fmt.setLocale(uloc, uloc); // services make no distinction between actual & valid
        return fmt;
    }
View Full Code Here

    /*
     * Test method for 'com.ibm.icu.text.DateFormat.setNumberFormat(NumberFormat)'
     */
    public final void testSetNumberFormat() {
        // no easy way to test effect of setting the number format
        NumberFormat nf = NumberFormat.getInstance();
        DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT);
        df.setNumberFormat(nf);
        // note, can't actually USE the dateformat since it changes the calendar
        assertEquals(nf, df.getNumberFormat());
    }
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;
        String idUppercase = id.toUpperCase();

        if (id != null && id.length() > kGMT_ID.length() &&
            idUppercase.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

    /*
     * Test method for 'com.ibm.icu.x.text.NumberFormat.NumberFormat(NumberFormat)'
     */
    public void testNumberFormat() {
        NumberFormat nf = new NumberFormat(java.text.NumberFormat.getInstance());
        assertEquals(nf, NumberFormat.getInstance());
    }
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.