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

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

Introduction

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

Prototype

public static NumberFormat getScientificFormat() 

Source Link

Document

Provides the standard scientific format for the default locale.

Usage

From source file:com.extjs.gxt.ui.client.util.Format.java

License:sencha.com license

/**
 * Provides the standard scientific format for the default locale.
 * /* w  ww  . ja v  a  2s .  c  om*/
 * @param value the value
 * @return the value
 */
public static String scientific(double value) {
    return NumberFormat.getScientificFormat().format(value);
}

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 ww w. j a  v a  2s  .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();
    }// w ww  .  jav a 2s .  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.
 */// w  w w.  ja v  a  2s .co  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:edu.caltech.ipac.firefly.data.form.DecimalFieldDef.java

private NumberFormat getNumberFormat() {
    NumberFormat nf;//from w w  w.  j a va  2s .  c  o  m
    if (sciNote) {
        nf = NumberFormat.getScientificFormat();
    } else {
        StringBuffer sb = new StringBuffer(9);
        if (precision == 0) {
            nf = NumberFormat.getFormat("#");
        } else {
            sb.append("#.");
            for (int i = 0; (i < precision); i++)
                sb.append("#");
            nf = NumberFormat.getFormat(sb.toString());
        }
    }
    return nf;
}

From source file:gov.nih.nci.ncicb.tcgaportal.level4.gwt.anomalysearch.client.filter.FilterSummaryPanel.java

protected String formatNumber(float number, boolean asPercent) {
    if (number <= 0) {
        return "";
    } else if (number < .01) {
        return NumberFormat.getScientificFormat().format(number) + (asPercent ? "%" : "");
    } else {// w w w.  ja  v  a2  s  .  co m
        return NumberFormat.getDecimalFormat().format(number) + (asPercent ? "%" : "");
    }
}

From source file:gov.nih.nci.ncicb.tcgaportal.level4.gwt.anomalysearch.client.results.ResultsTableGene.java

protected void populateDynamicCells(int resultsRow) {
    int displayRow = resultsRow + 1;
    ResultValue[] columnResultValues = results.getRow(resultsRow).getColumnResults();

    for (int resultsCol = 0; resultsCol < numCols; resultsCol++) {
        int displayCol = firstDynamicIdx + resultsCol;
        if (rowHasSuppressedGene.get(displayRow)) {
            displayCol--;//from www  .j a va  2s. co m
        }
        Double pValueAnnotation = (Double) columnResultValues[resultsCol]
                .getValueAnnotation(AnomalySearchConstants.VALUEANNOTATIONKEY_CORRELATION_PVALUE);
        String cellValue = getCellStringValue(columnResultValues[resultsCol]);

        if (pValueAnnotation != null) {
            String pValue = NumberFormat.getScientificFormat().format(pValueAnnotation);
            String celltext = cellValue + " (p-value:" + pValue + ")";
            setText(displayRow, displayCol, celltext);
            getCellFormatter().addStyleName(displayRow, displayCol, StyleConstants.RESULTS_TABLE_CORRELATION);
        } else {
            if (pivotLinkListener != null) {
                ResultRow row = results.getRow(resultsRow);

                String pivotId;
                ColumnType pivotColumn = results.getColumnTypes().get(resultsCol);
                pivotId = getPivotId(row, pivotColumn);
                HyperlinkHTML link = new HyperlinkHTML(cellValue, pivotId, pivotColumn);
                link.addStyleName("darkBlueText");
                link.addClickListener(pivotLinkListener);
                String ttText = TooltipTextMap.getInstance()
                        .get(AnomalySearchConstants.TOOLTIPKEY_RESULTS_PIVOTFROMGENE);
                link.addMouseListener(new TooltipListener(new HTML(ttText)));
                setWidget(displayRow, displayCol, link);
            } else {
                ColumnType col = results.getColumnTypes().get(resultsCol);
                if (isPivot && col instanceof MutationType) {
                    //show "yes" instead of "1"
                    double d = ((ResultDouble) columnResultValues[resultsCol]).getValue();
                    cellValue = (d == 1. ? "yes" : "no");
                }
                setText(displayRow, displayCol, cellValue);
            }
            getCellFormatter().addStyleName(displayRow, displayCol, StyleConstants.RESULTS_TABLE_CORRELATION);
        }
        getCellFormatter().addStyleName(displayRow, displayCol, StyleConstants.RESULTS_TABLE_CELL);
    }
}

From source file:gov.nih.nci.ncicb.tcgaportal.level4.gwt.anomalysearch.client.results.ResultsTablePathway.java

protected void populateConstantCells(int resultsRow) {
    int displayRow = resultsRow + 1;
    ResultRow row = results.getRow(resultsRow);
    Double fischer = (Double) row.getRowAnnotation(AnomalySearchConstants.ROWANNOTATIONKEY_PATHWAY_FISHER);
    if (fischer != null) {
        String sFischer = NumberFormat.getScientificFormat().format(fischer);
        setText(displayRow, 1, sFischer);
        getCellFormatter().addStyleName(displayRow, 1, StyleConstants.RESULTS_TABLE_CELL);
    }// ww  w .  ja v a  2  s.  co m
}

From source file:net.s17fabu.vip.gwt.showcase.client.content.i18n.CwNumberFormat.java

License:Apache License

/**
 * Update the selected pattern based on the pattern in the list.
 *///w ww  .j a v a 2 s.  c om
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:org.cruxframework.crux.gwt.client.NumberFormatUtil.java

License:Apache License

/**
 * Gets a NumberFormat object based on the patternString parameter. 
 * @param patternString//from  www .  j a  v  a 2  s. c  o m
 * @return
 */
public static NumberFormat getNumberFormat(String patternString) {
    NumberFormat result;

    if (DECIMAL_PATTERN.equals(patternString)) {
        result = NumberFormat.getDecimalFormat();
    } else if (CURRENCY_PATTERN.equals(patternString)) {
        result = NumberFormat.getCurrencyFormat();
    } else if (PERCENT_PATTERN.equals(patternString)) {
        result = NumberFormat.getPercentFormat();
    } else if (SCIENTIFIC_PATTERN.equals(patternString)) {
        result = NumberFormat.getScientificFormat();
    } else {
        result = NumberFormat.getFormat(patternString);
    }

    return result;
}