Examples of NumberFormat


Examples of com.google.gwt.i18n.client.NumberFormat

     *
     * @param ms
     * @return
     */
    static String formatDuration(int ms) {
        NumberFormat fmt = NumberFormat.getFormat("00");
        String seconds = fmt.format((ms / 1000) % 60);
        String minutes = fmt.format((ms / (1000 * 60)) % 60);
        String hours = fmt.format((ms / (1000 * 60 * 60)) % 24);

        String millis = NumberFormat.getFormat("000").format(ms % 1000);

        return hours + "h " + minutes + "m " + seconds + "s " + millis + "ms";
    }
View Full Code Here

Examples of com.google.gwt.visualization.client.formatters.NumberFormat

        options.setNegativeColor("red");
        options.setNegativeParens(false);
        options.setPrefix("$");
        options.setSuffix("%");

        NumberFormat formatter = NumberFormat.create(options);
        formatter.format(dataTable, 0);
        assertEquals("$-3_142%", dataTable.getFormattedValue(0, 0));
        // TODO(zundel): Unit tests are curently broken with this assertion.
        // dataTable.getProperty() returns null.
        // assertEquals("color:red;",
        // dataTable.getProperty(0, 0, "__td-style"));
View Full Code Here

Examples of com.google.i18n.phonenumbers.Phonemetadata.NumberFormat

    assertEquals("000", phoneUtil.formatNumberForMobileDialing(auNumber, RegionCode.AU, false));
    assertEquals("", phoneUtil.formatNumberForMobileDialing(auNumber, RegionCode.NZ, false));
  }

  public void testFormatByPattern() {
    NumberFormat newNumFormat = new NumberFormat();
    newNumFormat.setPattern("(\\d{3})(\\d{3})(\\d{4})");
    newNumFormat.setFormat("($1) $2-$3");
    List<NumberFormat> newNumberFormats = new ArrayList<NumberFormat>();
    newNumberFormats.add(newNumFormat);

    assertEquals("(650) 253-0000", phoneUtil.formatByPattern(US_NUMBER, PhoneNumberFormat.NATIONAL,
                                                             newNumberFormats));
    assertEquals("+1 (650) 253-0000", phoneUtil.formatByPattern(US_NUMBER,
                                                                PhoneNumberFormat.INTERNATIONAL,
                                                                newNumberFormats));
    assertEquals("tel:+1-650-253-0000", phoneUtil.formatByPattern(US_NUMBER,
                                                                  PhoneNumberFormat.RFC3966,
                                                                  newNumberFormats));

    // $NP is set to '1' for the US. Here we check that for other NANPA countries the US rules are
    // followed.
    newNumFormat.setNationalPrefixFormattingRule("$NP ($FG)");
    newNumFormat.setFormat("$1 $2-$3");
    assertEquals("1 (242) 365-1234",
                 phoneUtil.formatByPattern(BS_NUMBER, PhoneNumberFormat.NATIONAL,
                                           newNumberFormats));
    assertEquals("+1 242 365-1234",
                 phoneUtil.formatByPattern(BS_NUMBER, PhoneNumberFormat.INTERNATIONAL,
                                           newNumberFormats));

    newNumFormat.setPattern("(\\d{2})(\\d{5})(\\d{3})");
    newNumFormat.setFormat("$1-$2 $3");
    newNumberFormats.set(0, newNumFormat);

    assertEquals("02-36618 300",
                 phoneUtil.formatByPattern(IT_NUMBER, PhoneNumberFormat.NATIONAL,
                                           newNumberFormats));
    assertEquals("+39 02-36618 300",
                 phoneUtil.formatByPattern(IT_NUMBER, PhoneNumberFormat.INTERNATIONAL,
                                           newNumberFormats));

    newNumFormat.setNationalPrefixFormattingRule("$NP$FG");
    newNumFormat.setPattern("(\\d{2})(\\d{4})(\\d{4})");
    newNumFormat.setFormat("$1 $2 $3");
    newNumberFormats.set(0, newNumFormat);
    assertEquals("020 7031 3000",
                 phoneUtil.formatByPattern(GB_NUMBER, PhoneNumberFormat.NATIONAL,
                                           newNumberFormats));

    newNumFormat.setNationalPrefixFormattingRule("($NP$FG)");
    assertEquals("(020) 7031 3000",
                 phoneUtil.formatByPattern(GB_NUMBER, PhoneNumberFormat.NATIONAL,
                                           newNumberFormats));

    newNumFormat.setNationalPrefixFormattingRule("");
    assertEquals("20 7031 3000",
                 phoneUtil.formatByPattern(GB_NUMBER, PhoneNumberFormat.NATIONAL,
                                           newNumberFormats));

    assertEquals("+44 20 7031 3000",
View Full Code Here

Examples of com.googlecode.gwt.charts.client.format.NumberFormat

        dateFormatOptions.setFormatType(FormatType.MEDIUM);
        DateFormat dateFormat = DateFormat.create(dateFormatOptions);

        NumberFormatOptions numberFormatOptions = NumberFormatOptions.create();
        numberFormatOptions.setPattern("#,###.##");
        NumberFormat numberFormat = NumberFormat.create(numberFormatOptions);

        for (int i = 0; i < gTable.getNumberOfColumns(); i++) {
            com.googlecode.gwt.charts.client.ColumnType type = gTable.getColumnType(i);
            if (com.googlecode.gwt.charts.client.ColumnType.DATE.equals(type)) {
                dateFormat.format(gTable, i);
            }
            else if (com.googlecode.gwt.charts.client.ColumnType.NUMBER.equals(type)) {
                numberFormat.format(gTable, i);
            }
        }
        return gTable;
    }
View Full Code Here

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

Examples of java.text.NumberFormat

               Object value, boolean isSelected, boolean hasFocus,
               int row, int column) {
            value = ((CatalogPieceOfFurniture)value).getPrice();
            if (value != null) {
              String currency = preferences.getCurrency();
              NumberFormat currencyFormat;
              if (currency != null) {
                currencyFormat = DecimalFormat.getCurrencyInstance();
                currencyFormat.setCurrency(Currency.getInstance(currency));
              } else {
                currencyFormat = new DecimalFormat("##0.00");
              }
              value = currencyFormat.format(value);
            } else {
              value = "";
            }
            setHorizontalAlignment(JLabel.RIGHT);
            return super.getTableCellRendererComponent(
View Full Code Here

Examples of java.text.NumberFormat

          public Component getTableCellRendererComponent(JTable table,
               Object value, boolean isSelected, boolean hasFocus,
               int row, int column) {
            BigDecimal valueAddedTaxPercentage = ((CatalogPieceOfFurniture)value).getValueAddedTaxPercentage();
            if (valueAddedTaxPercentage != null) {
              NumberFormat percentInstance = DecimalFormat.getPercentInstance();
              percentInstance.setMinimumFractionDigits(valueAddedTaxPercentage.scale() - 2);
              value = percentInstance.format(valueAddedTaxPercentage);
            } else {
              value = "";
            }
            setHorizontalAlignment(JLabel.RIGHT);
            return super.getTableCellRendererComponent(
View Full Code Here

Examples of java.text.NumberFormat

        decoratedField.append(valueString);
        break;

      case FieldDecoration.moneyType:
        // display the string to currency format
        NumberFormat numFormatter = NumberFormat.getCurrencyInstance(this.locale);
        if (content == null) {
          content = "0";
        }
        valueString = content.toString();
        Double doubleValue = new Double(valueString);
        if (doubleValue != null) {
          String contentFormated = numFormatter.format(doubleValue.doubleValue());
          decoratedField.append(contentFormated);
        }
        break;
      case FieldDecoration.hourType:
        // We are using the old version of mysql we must have to do this..
View Full Code Here

Examples of java.text.NumberFormat

   * ���ͬʱ�������������Ͷ���,�����
   * @return
   */
  public String festival(){
    long[] ds = LunarCalendar.today();
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(0);
    nf.setMinimumIntegerDigits(2);
    String nongli = nf.format(ds[1]) + nf.format(ds[2]);
    Calendar cal = Calendar.getInstance();
    String yangli = nf.format(cal.get(Calendar.MONTH)+1)+nf.format(cal.get(Calendar.DATE));
    //System.out.printf("nongli=%s,yangli=%s\r\n",nongli,yangli);
    String f_nl = getMessage(request, "festival", 'Y'+nongli);
    String f_yl = getMessage(request, "festival", yangli);
    if(f_nl!=null && f_yl!=null)
      return f_yl + "," + f_nl;
View Full Code Here

Examples of java.text.NumberFormat

    }

    int cache_index = (precision << 2) + ((bTruncateZeros ? 1 : 0) << 1)
        + (bRound ? 1 : 0);

    NumberFormat nf = null;

    if (cache_index < cached_number_formats.length) {
      nf = cached_number_formats[cache_index];
    }

    if (nf == null) {
      nf = NumberFormat.getNumberInstance();
      nf.setGroupingUsed(false); // no commas
      if (!bTruncateZeros) {
        nf.setMinimumFractionDigits(precision);
      }
      if (bRound) {
        nf.setMaximumFractionDigits(precision);
      }

      if (cache_index < cached_number_formats.length) {
        cached_number_formats[cache_index] = nf;
      }
    }

    return nf.format(tValue);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.