Example usage for com.google.gwt.i18n.client NumberFormat getDecimalFormat

List of usage examples for com.google.gwt.i18n.client NumberFormat getDecimalFormat

Introduction

In this page you can find the example usage for com.google.gwt.i18n.client NumberFormat getDecimalFormat.

Prototype

public static NumberFormat getDecimalFormat() 

Source Link

Document

Provides the standard decimal format for the default locale.

Usage

From source file:com.gafactory.core.client.ui.grids.BaseListGrid.java

License:Open Source License

protected Column<T, String> addFormattedNumberColumn(final ValueProvider<T, ? extends Number> valueProvider,
        String header, int width, boolean sortable) {
    return addColumn(new TextColumn<T>() {
        @Override/*  w  ww.  ja v a2s.c o  m*/
        public String getValue(T object) {
            if (object != null) {
                Number value = valueProvider.getValue(object);
                if (value != null) {
                    return NumberFormat.getDecimalFormat().format(value);
                }
            }
            return EMPTY_STRING;
        }
    }, header, width, sortable, sortable ? valueProvider.getPath() : null);
}

From source file:com.gafactory.core.client.ui.grids.BaseListGrid.java

License:Open Source License

protected Column<T, String> addNumberColumn(final ValueProvider<T, ? extends Number> valueProvider,
        String header, int width, boolean sortable) {
    return addColumn(new TextColumn<T>() {
        @Override//  www .  ja  va 2  s. c  om
        public String getValue(T object) {
            if (object != null) {
                Number value = valueProvider.getValue(object);
                if (value != null) {
                    //                        return NUMBER_FORMAT.format(value);
                    return NumberFormat.getDecimalFormat().format(value);

                }

            }
            return EMPTY_STRING;
        }
    }, header, width, sortable, sortable ? valueProvider.getPath() : null);
}

From source file:com.google.gwt.examples.NumberFormatExample.java

public void onModuleLoad() {
    NumberFormat fmt = NumberFormat.getDecimalFormat();
    double value = 12345.6789;
    String formatted = fmt.format(value);
    // Prints 1,2345.6789 in the default locale
    GWT.log("Formatted string is" + formatted);

    // Turn a string back into a double
    value = NumberFormat.getDecimalFormat().parse("12345.6789");
    GWT.log("Parsed value is" + value);

    // Scientific notation
    value = 12345.6789;/*from w w w.  j ava 2  s.c  o m*/
    formatted = NumberFormat.getScientificFormat().format(value);
    // prints 1.2345E4 in the default locale
    GWT.log("Formatted string is" + formatted);

    // Currency
    fmt = NumberFormat.getCurrencyFormat();
    formatted = fmt.format(123456.7899);
    // prints US$123,456.79 in the default locale or $123,456.79 in the en_US
    // locale
    GWT.log("Formatted currency is" + formatted);

    // Custom format
    value = 12345.6789;
    formatted = NumberFormat.getFormat("000000.000000").format(value);
    // prints 012345.678900 in the default locale
    GWT.log("Formatted string is" + formatted);
}

From source file:com.google.gwt.sample.i18n.client.NumberFormatExampleController.java

License:Apache License

@Override
protected String doGetPattern(String patternKey) {
    if ("currency".equals(patternKey)) {
        return NumberFormat.getCurrencyFormat().getPattern();
    }//from   ww w  . j av a2  s  .c o  m

    if ("decimal".equals(patternKey)) {
        return NumberFormat.getDecimalFormat().getPattern();
    }

    if ("scientific".equals(patternKey)) {
        return NumberFormat.getScientificFormat().getPattern();
    }

    if ("percent".equals(patternKey)) {
        return NumberFormat.getPercentFormat().getPattern();
    }

    throw new IllegalArgumentException("Unknown pattern key '" + patternKey + "'");
}

From source file:com.google.gwt.sample.showcase.client.content.i18n.CwNumberFormat.java

License:Apache License

/**
 * Update the selected pattern based on the pattern in the list.
 *//*from   ww w.  j  a  v a 2 s . c  o m*/
@ShowcaseSource
private void updatePattern() {
    switch (patternList.getSelectedIndex()) {
    case 0:
        activeFormat = NumberFormat.getDecimalFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;
    case 1:
        activeFormat = NumberFormat.getCurrencyFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;
    case 2:
        activeFormat = NumberFormat.getScientificFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;
    case 3:
        activeFormat = NumberFormat.getPercentFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;
    case 4:
        patternBox.setEnabled(true);
        String pattern = patternBox.getText();
        try {
            activeFormat = NumberFormat.getFormat(pattern);
        } catch (IllegalArgumentException e) {
            showErrorMessage(constants.cwNumberFormatInvalidPattern());
            return;
        }
        break;
    }

    // Update the formatted value
    updateFormattedValue();
}

From source file:com.google.gwt.sample.stockwatcher.client.ChartUtilities.java

private static Number convertToNumber(String unformattedData) {
    String data = "";
    if (unformattedData.contains("."))
        data = unformattedData.substring(0,
                Math.min(unformattedData.indexOf('.') + 3, unformattedData.length()));
    else//from  w  ww .j  a  v  a  2s . com
        data = unformattedData;
    Number value;
    try {
        value = Integer.parseInt(data);
    } catch (NumberFormatException e) {
        value = NumberFormat.getDecimalFormat().parse(data);
    } //assign value
    return value;
}

From source file:com.itgp.gwtviz.client.ui.cell.client.StringCellAsNumber.java

License:Open Source License

/**
 * Construct a new {@link NumberCell} using decimal format and a {@link SimpleSafeHtmlRenderer}.
 *///from  w  w w  . ja v a2 s  .c o  m
public StringCellAsNumber() {
    this(NumberFormat.getDecimalFormat(), SimpleSafeHtmlRenderer.getInstance());
}

From source file:com.itgp.gwtviz.client.ui.cell.client.StringCellAsNumber.java

License:Open Source License

/**
 * Construct a new {@link NumberCell} using decimal format and the given {@link SafeHtmlRenderer}.
 *
 * @param renderer//w  ww  .  j  av a2s.c o  m
 *            the {@link SafeHtmlRenderer} used to render the formatted number as HTML
 */
public StringCellAsNumber(SafeHtmlRenderer<String> renderer) {
    this(NumberFormat.getDecimalFormat(), renderer);
}

From source file:com.ocado.rangeui.client.gui.component.grid.column.EditNumberCell.java

/**
 * Construct a new EditTextCell that will use a
 * {@link SimpleSafeHtmlRenderer}./*from  w w  w  . j  a  va2s  .  co  m*/
 */
public EditNumberCell() {
    this(NumberFormat.getDecimalFormat(), SimpleSafeHtmlRenderer.getInstance());
}

From source file:com.ocado.rangeui.client.gui.component.grid.column.EditNumberCell.java

/**
 * Construct a new EditTextCell that will use a given {@link SafeHtmlRenderer}
 * to render the value when not in edit mode.
 *
   * @param renderer/*  w  w  w  .ja  v a 2s .  co m*/
   * @return  */
//  public EditNumberCell(NumberFormat format, SafeHtmlRenderer<String> renderer) {
//    super("click", "keyup", "keydown", "blur");
//    if (template == null) {
//      template = GWT.create(Template.class);
//    }
//    if (format == null) {
//      throw new IllegalArgumentException("format == null");
//    }
//    if (renderer == null) {
//      throw new IllegalArgumentException("renderer == null");
//    }
//    this.format = format;
//    this.renderer = renderer;
//  }

public EditNumberCell(SafeHtmlRenderer<String> renderer) {
    this(NumberFormat.getDecimalFormat(), renderer);
}