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

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

Introduction

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

Prototype

public String format(Number number) 

Source Link

Document

This method formats a Number to produce a string.

Usage

From source file:ar.com.kyol.jet.client.wrappers.HTMLWrapper.java

License:Open Source License

/**
 * Instantiates a new hTML wrapper.//from w  w w . j av  a 2s . c o m
 *
 * @param objSetter the obj setter
 * @param html the html
 */
public HTMLWrapper(ObjectSetter objSetter, HTML html) {
    super(false);
    this.objSetter = objSetter;
    this.html = html;
    if (objSetter.getValue() == null) {
        html.setText("");
    } else {
        NumberFormat.setForcedLatinDigits(true);
        if (objSetter.getValue() instanceof Float) {
            NumberFormat nf = NumberFormat.getFormat(getFormat("0.00"));
            Float valor = (Float) objSetter.getValue();
            html.setText(nf.format(valor));
        } else if (objSetter.getValue() instanceof Double) {
            NumberFormat nf = NumberFormat.getFormat(getFormat("0.00"));
            Double valor = (Double) objSetter.getValue();
            html.setText(nf.format(valor));
        } else if (objSetter.getValue() instanceof Long) {
            NumberFormat nf = NumberFormat.getFormat(getFormat("0"));
            Long valor = (Long) objSetter.getValue();
            html.setText(nf.format(valor));
        } else if (objSetter.getValue() instanceof Integer) {
            NumberFormat nf = NumberFormat.getFormat(getFormat("0"));
            Integer valor = (Integer) objSetter.getValue();
            html.setText(nf.format(valor));
        } else if (objSetter.getValue() instanceof java.util.Date) {
            java.util.Date utilDate = (java.util.Date) objSetter.getValue();
            html.setText(DateTimeFormat.getFormat(getFormat("dd/MM/yyyy")).format(utilDate));
        } else if (objSetter.getValue() instanceof java.sql.Date) {
            java.sql.Date sqlDate = (java.sql.Date) objSetter.getValue();
            html.setText(DateTimeFormat.getFormat(getFormat("dd/MM/yyyy")).format(sqlDate));
        } else if (objSetter.getValue() instanceof Timestamp) {
            Timestamp ts = (Timestamp) objSetter.getValue();
            html.setText(DateTimeFormat.getFormat(getFormat("dd/MM/yyyy")).format(ts));
        } else {
            html.setText(objSetter.getValue().toString());
        }
    }

    initWidget(html);
}

From source file:ar.com.kyol.jet.client.wrappers.Wrapper.java

License:Open Source License

/**
 * Formats a float value with the associated objSetter.getFormat
 * //from  w ww.  j  a  v a  2 s . c  o m
 * @param value
 * @return value formatted or not, and "formatError!" if value can't be parsed to float 
 */
protected String formatValue(String value) {
    String returnValue = value;
    if (objSetter.getFormat() != null) {
        try {
            NumberFormat formatter = NumberFormat.getFormat(objSetter.getFormat());
            returnValue = formatter.format(Float.parseFloat(value));
        } catch (Exception e) {
            log.log(Level.SEVERE, "formatter error in setter " + objSetter.getSetter() + " with format "
                    + objSetter.getFormat());
            returnValue = "formatError!";
        }
    }
    return returnValue;
}

From source file:cimav.client.view.catalogos.tabulador.NivelesUi.java

/**
 * Add the columns to the table.//from  www .  ja  v  a2  s  .co  m
 */
private void initTableColumns(ColumnSortEvent.ListHandler<Tabulador> sortHandler) {

    // ID
    Column<Tabulador, String> idCol = new Column<Tabulador, String>(new TextCell()) {
        @Override
        public String getValue(Tabulador object) {
            return object.getId().toString();
        }
    };
    dataGrid.addColumn(idCol, "ID");
    dataGrid.setColumnWidth(idCol, 40, Style.Unit.PX);

    // Code
    Column<Tabulador, String> codigoCol = new Column<Tabulador, String>((new TextCell())) {
        @Override
        public String getValue(Tabulador object) {
            return object.getCode();
        }
    };
    codigoCol.setSortable(true);
    sortHandler.setComparator(codigoCol, new Comparator<Tabulador>() {
        @Override
        public int compare(Tabulador o1, Tabulador o2) {
            return o1.getCode().compareTo(o2.getCode());
        }
    });
    dataGrid.addColumn(codigoCol, "Cdigo");
    dataGrid.setColumnWidth(codigoCol, 70, Style.Unit.PX);

    // Sueldo
    Column<Tabulador, String> sueldoCol = new Column<Tabulador, String>(new TextCell()) {
        @Override
        public String getValue(Tabulador object) {
            NumberFormat fmt = NumberFormat.getCurrencyFormat();
            String output = object.getSueldo().toString();
            Double value = Double.parseDouble(output);
            String formatted = fmt.format(value);
            return formatted;
        }
    };
    sueldoCol.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    sueldoCol.setSortable(true);
    sortHandler.setComparator(sueldoCol, new Comparator<Tabulador>() {
        @Override
        public int compare(Tabulador o1, Tabulador o2) {
            return o1.getSueldo().compareTo(o2.getSueldo());
        }
    });
    dataGrid.addColumn(sueldoCol, "Sueldo");
    dataGrid.setColumnWidth(sueldoCol, 60, Style.Unit.PX);

    // matDidacticos
    Column<Tabulador, String> matDidacticosCol = new Column<Tabulador, String>(new TextCell()) {
        @Override
        public String getValue(Tabulador object) {
            return object.getMatDidacticos().toString();
        }
    };
    dataGrid.addColumn(matDidacticosCol, "Mat. Didacticos");
    dataGrid.setColumnWidth(matDidacticosCol, 60, Style.Unit.PX);

    // honorarios
    Column<Tabulador, String> honorariosCol = new Column<Tabulador, String>(new TextCell()) {
        @Override
        public String getValue(Tabulador object) {
            return object.getHonorarios().toString();
        }
    };
    dataGrid.addColumn(honorariosCol, "Honorarios");
    dataGrid.setColumnWidth(honorariosCol, 60, Style.Unit.PX);

    // compGarantizadaCol
    Column<Tabulador, String> compGarantizadaCol = new Column<Tabulador, String>(new TextCell()) {
        @Override
        public String getValue(Tabulador object) {
            return object.getCompGarantizada().toString();
        }
    };
    dataGrid.addColumn(compGarantizadaCol, "Comp. Garantizada");
    dataGrid.setColumnWidth(compGarantizadaCol, 60, Style.Unit.PX);

    // cargaAdmin
    Column<Tabulador, String> cargaAdminCol = new Column<Tabulador, String>(new TextCell()) {
        @Override
        public String getValue(Tabulador object) {
            return object.getCargaAdmin().toString();
        }
    };
    dataGrid.addColumn(cargaAdminCol, "Carga Admin.");
    dataGrid.setColumnWidth(cargaAdminCol, 60, Style.Unit.PX);

}

From source file:cimav.client.view.common.Utils.java

/**
 * @param bigDecimal/*from  ww w  .  j  av a 2s.co m*/
 * @return $123,451.60
 */
public static String formatCurrency(BigDecimal bigDecimal) {
    NumberFormat fmt = NumberFormat.getCurrencyFormat();
    String formatted = fmt.format(bigDecimal);
    return formatted;
}

From source file:cimav.client.view.common.Utils.java

/**
 * @param bigDecimal/*from www  .  ja v  a  2  s .c  o m*/
 * @return 123,452.60
 */
public static String formatCantidad(BigDecimal bigDecimal) {
    if (bigDecimal == null) {
        bigDecimal = BigDecimal.ZERO;
    }
    NumberFormat fmt = NumberFormat.getFormat("###,###,###.00");
    String formatted = fmt.format(bigDecimal);
    return formatted;
}

From source file:com.arcbees.beestore.client.application.CurrencyFormat.java

License:Apache License

public String format(float number) {
    NumberFormat numberFormat = NumberFormat.getFormat(CURRENCY_FORMAT);

    return numberFormat.format(number);
}

From source file:com.client.celltable.SimplePager.java

License:Apache License

/**
 * Get the text to display in the pager that reflects the state of the
 * pager./*from www  .  j a va  2s. co  m*/
 * 
 * @return the text
 */
protected String createText() {
    // Default text is 1 based.
    NumberFormat formatter = NumberFormat.getFormat("#,###");
    HasRows display = getDisplay();
    Range range = display.getVisibleRange();
    int pageStart = range.getStart() + 1;
    int pageSize = range.getLength();
    int dataSize = display.getRowCount();
    int endIndex = Math.min(dataSize, pageStart + pageSize - 1);
    endIndex = Math.max(pageStart, endIndex);
    boolean exact = display.isRowCountExact();
    return formatter.format(pageStart) + "-" + formatter.format(endIndex) + (exact ? " of " : " of over ")
            + formatter.format(dataSize);
}

From source file:com.cooper.client.ItemListGrid.java

License:Open Source License

public ItemListGrid(DataSource supplyItemDS) {

    setDataSource(supplyItemDS);//from   ww w  .  j  av a  2  s  .co m
    setUseAllDataSourceFields(true);

    ListGridField itemName = new ListGridField("itemName", "Name");
    itemName.setShowHover(true);
    ListGridField unitCost = new ListGridField("unitCost");

    unitCost.setCellFormatter(new CellFormatter() {
        public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
            if (value == null)
                return null;
            try {
                NumberFormat nf = NumberFormat.getFormat("##0.00");
                return "$" + nf.format(((Number) value).floatValue());
            } catch (Exception e) {
                return value.toString();
            }
        }
    });

    SpinnerItem spinnerItem = new SpinnerItem();
    spinnerItem.setStep(0.01);
    unitCost.setEditorType(spinnerItem);

    ListGridField sku = new ListGridField("SKU");
    sku.setCanEdit(false);

    ListGridField description = new ListGridField("description");
    description.setShowHover(true);

    ListGridField category = new ListGridField("category");
    category.setCanEdit(false);

    ListGridField inStock = new ListGridField("inStock");
    inStock.setWidth(55);
    inStock.setAlign(Alignment.CENTER);

    ListGridField nextShipment = new ListGridField("nextShipent");
    nextShipment.setShowIfCondition(new ListGridFieldIfFunction() {
        public boolean execute(ListGrid grid, ListGridField field, int fieldNum) {
            return false;
        }
    });

    setFields(itemName, unitCost, sku, description, category, inStock);
    setCanEdit(true);
    setCanDragRecordsOut(true);
    setHoverWidth(200);
    setHoverHeight(20);
    setSelectionType(SelectionStyle.SINGLE);
}

From source file:com.demo.gwt.app.ItemListGrid.java

License:Open Source License

public ItemListGrid(DataSource supplyItemDS) {

    setDataSource(supplyItemDS);/*from   w  w  w.  j a v  a2 s .com*/
    setUseAllDataSourceFields(true);

    ListGridField itemName = new ListGridField("itemName", "Name");
    itemName.setShowHover(true);
    ListGridField unitCost = new ListGridField("unitCost");

    unitCost.setCellFormatter(new CellFormatter() {
        public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
            if (value == null)
                return null;
            try {
                NumberFormat nf = NumberFormat.getFormat("##0.00");
                return "$" + nf.format(((Number) value).floatValue());
            } catch (Exception e) {
                return value.toString();
            }
        }
    });

    SpinnerItem spinnerItem = new SpinnerItem();
    spinnerItem.setStep(0.01);
    unitCost.setEditorProperties(spinnerItem);

    ListGridField sku = new ListGridField("SKU");
    sku.setCanEdit(false);

    ListGridField description = new ListGridField("description");
    description.setShowHover(true);

    ListGridField category = new ListGridField("category");
    category.setCanEdit(false);

    ListGridField inStock = new ListGridField("inStock");
    inStock.setWidth(55);
    inStock.setAlign(Alignment.CENTER);

    ListGridField nextShipment = new ListGridField("nextShipent");
    nextShipment.setShowIfCondition(new ListGridFieldIfFunction() {
        public boolean execute(ListGrid grid, ListGridField field, int fieldNum) {
            return false;
        }
    });

    setFields(itemName, unitCost, sku, description, category, inStock);
    setCanEdit(true);
    setCanDragRecordsOut(true);
    setHoverWidth(200);
    setHoverHeight(20);
    setSelectionType(SelectionStyle.SINGLE);
}

From source file:com.ephesoft.gxt.admin.client.presenter.kvextraction.AdvancedKVExtraction.AdvancedKVExtractionInputPanelPresenter.java

License:Open Source License

private Float getRange(Float val) {
    NumberFormat format = NumberFormat.getFormat(".##");
    Float range = val;
    String str = format.format(range);
    range = Float.valueOf(str);/*from w  ww.  j av a 2s  .  co m*/
    return range;
}