Example usage for java.text NumberFormat getNumberInstance

List of usage examples for java.text NumberFormat getNumberInstance

Introduction

In this page you can find the example usage for java.text NumberFormat getNumberInstance.

Prototype

public static final NumberFormat getNumberInstance() 

Source Link

Document

Returns a general-purpose number format for the current default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:com.cypress.cysmart.BLEServiceFragments.RSCService.java

/**
 * Display live running data/*from ww w  .j av  a  2  s.  com*/
 */
private void displayLiveData(final ArrayList<String> rsc_data) {
    if (rsc_data != null) {
        try {
            /**
             * Number formatting to two fractional decimals
             */
            Number cycledDist = NumberFormat.getInstance().parse(rsc_data.get(1));
            Number averageSpeed = NumberFormat.getInstance().parse(rsc_data.get(0));
            NumberFormat distformatter = NumberFormat.getNumberInstance();
            distformatter.setMinimumFractionDigits(2);
            distformatter.setMaximumFractionDigits(2);
            String distRan = distformatter.format(cycledDist);
            avgSpeed = distformatter.format(averageSpeed);
            mDistanceRan.setText(distRan);
            mAverageSpeed.setText(avgSpeed);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        if (mCurrentTime == 0) {
            mGraphLastXValue = 0;
            mCurrentTime = Utils.getTimeInSeconds();
        } else {
            mPreviosTime = mCurrentTime;
            mCurrentTime = Utils.getTimeInSeconds();
            mGraphLastXValue = mGraphLastXValue + (mCurrentTime - mPreviosTime) / 1000;
        }
        try {
            float val = Float.valueOf(avgSpeed);
            mDataSeries.add(mGraphLastXValue, val);
            mChart.repaint();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.clustercontrol.jmx.factory.RunMonitorJmx.java

/**
 * ????/* www . j  a  v  a 2s.co m*/
 */
@Override
public String getMessageOrg(int result) {
    String message;
    if (exception == null) {
        if (Double.isNaN(m_value)) {
            message = NaN;
        } else {
            String name = "?";
            try {
                JmxMasterInfo jmxMasterInfo = QueryUtil.getJmxMasterInfoPK(jmx.getMasterId());
                name = jmxMasterInfo.getName();
            } catch (MonitorNotFound e) {
                m_log.warn("not found : " + jmx.getMasterId());
            }
            if (m_prevNullchk) {
                message = name + " : ";
                m_prevNullchk = !m_prevNullchk;
                return message;
            }
            message = name + " : " + NumberFormat.getNumberInstance().format(m_value);
        }
    } else {
        String name = "?";
        try {
            JmxMasterInfo jmxMasterInfo = QueryUtil.getJmxMasterInfoPK(jmx.getMasterId());
            name = jmxMasterInfo.getName();
        } catch (MonitorNotFound e) {
            m_log.warn("not found : " + jmx.getMasterId());
        }
        message = name + " : " + exception.getMessage();
    }
    return message;
}

From source file:pcgen.util.Logging.java

/**
 * Generate the memory report string//from  ww w.  j  a  v  a2s.  c o m
 * @return the memory report string
 */
public static String memoryReportStr() {
    Runtime rt = Runtime.getRuntime();
    NumberFormat numFmt = NumberFormat.getNumberInstance();
    StringBuilder sb = new StringBuilder("Memory: ");
    sb.append(numFmt.format(rt.totalMemory() / 1024.0));
    sb.append("Kb total, ");
    sb.append(numFmt.format(rt.freeMemory() / 1024.0));
    sb.append("Kb free, ");
    sb.append(numFmt.format(rt.maxMemory() / 1024.0));
    sb.append("Kb max.");
    return sb.toString();
}

From source file:org.yccheok.jstock.gui.OptionsSellAdvisorJPanel.java

private JFormattedTextField getPercentageJFormattedTextField() {
    NumberFormat format = NumberFormat.getNumberInstance();
    NumberFormatter formatter = new NumberFormatter(format);
    formatter.setMinimum(0.0);/*from  www. j av a2s.c o m*/
    formatter.setMaximum(null);
    formatter.setValueClass(Double.class);
    JFormattedTextField field = new JFormattedTextField(formatter);

    return field;
}

From source file:net.sf.mzmine.modules.peaklistmethods.peakpicking.adap3decompositionV1_5.ADAP3DecompositionV1_5SetupDialog.java

/**
 * Cluster list of PeakInfo based on the chromatographic shapes
 * //from   ww w  . ja v  a2  s  .c  o m
 * @param peaks list of ADAP peaks
 * @param outClusters output of clusters
 * @param outText output of tooltip text
 * @param outColors output of colors
 */

private void shapeCluster(List<Peak> peaks, List<List<NavigableMap<Double, Double>>> outClusters,
        List<List<String>> outText, List<Double> outColors) {
    NumberFormat numberFormat = NumberFormat.getNumberInstance();

    Double edgeToHeightRatio = parameterSet.getParameter(ADAP3DecompositionV1_5Parameters.EDGE_TO_HEIGHT_RATIO)
            .getValue();
    Double deltaToHeightRatio = parameterSet
            .getParameter(ADAP3DecompositionV1_5Parameters.DELTA_TO_HEIGHT_RATIO).getValue();
    Boolean useIsShared = parameterSet.getParameter(ADAP3DecompositionV1_5Parameters.USE_ISSHARED).getValue();
    Double shapeSimThreshold = parameterSet.getParameter(ADAP3DecompositionV1_5Parameters.SHAPE_SIM_THRESHOLD)
            .getValue();
    Double minModelPeakSharpness = parameterSet
            .getParameter(ADAP3DecompositionV1_5Parameters.MIN_MODEL_SHARPNESS).getValue();
    List<Range<Double>> deprecatedMZValues = parameterSet
            .getParameter(ADAP3DecompositionV1_5Parameters.MZ_VALUES).getValue();

    if (edgeToHeightRatio == null || deltaToHeightRatio == null || useIsShared == null
            || shapeSimThreshold == null || minModelPeakSharpness == null || deprecatedMZValues == null)
        return;

    List<Peak> modelPeakCandidates = TwoStepDecomposition.filterPeaks(peaks, useIsShared, edgeToHeightRatio,
            deltaToHeightRatio, minModelPeakSharpness, deprecatedMZValues);

    if (modelPeakCandidates.isEmpty())
        return;

    List<List<Peak>> clusters = TwoStepDecomposition.getShapeClusters(modelPeakCandidates, shapeSimThreshold);

    outClusters.clear();
    outText.clear();
    outColors.clear();

    Random rand = new Random();
    rand.setSeed(0);

    int colorIndex = 0;
    final int numColors = 10;
    final double[] colors = new double[numColors];

    for (int i = 0; i < numColors; ++i)
        colors[i] = rand.nextDouble();

    for (List<Peak> cluster : clusters) {
        List<NavigableMap<Double, Double>> c = new ArrayList<>(cluster.size());

        List<String> texts = new ArrayList<>(cluster.size());

        for (Peak peak : cluster) {
            c.add(peak.getChromatogram());
            texts.add(peak.getInfo() + "\nSharpness: "
                    + numberFormat.format(FeatureTools.sharpnessYang(peak.getChromatogram())));
        }
        outClusters.add(c);
        outText.add(texts);

        outColors.add(colors[colorIndex % numColors]);
        ++colorIndex;
    }
}

From source file:InputVerificationDemo.java

private void setUpFormats() {
    moneyFormat = (NumberFormat) NumberFormat.getNumberInstance();

    percentFormat = NumberFormat.getNumberInstance();
    percentFormat.setMinimumFractionDigits(3);

    decimalFormat = (DecimalFormat) NumberFormat.getNumberInstance();
    decimalFormat.setParseIntegerOnly(true);

    paymentFormat = (DecimalFormat) NumberFormat.getNumberInstance();
    paymentFormat.setMaximumFractionDigits(2);
    paymentFormat.setNegativePrefix("(");
    paymentFormat.setNegativeSuffix(")");
}

From source file:biz.wolschon.fileformats.gnucash.baseclasses.SimpleAccount.java

/**
 *
 * @return The currency-format to use for formating.
 *//*from   ww w. j a  v a2s  .com*/
public NumberFormat getCurrencyFormat() {
    if (currencyFormat == null) {
        currencyFormat = NumberFormat.getCurrencyInstance();
    }

    // the currency may have changed
    if (this.getCurrencyNameSpace().equals(GnucashAccount.CURRENCYNAMESPACE_CURRENCY)) {
        Currency currency = getCurrency();
        currencyFormat.setCurrency(currency);
    } else {
        currencyFormat = NumberFormat.getNumberInstance();
    }

    return currencyFormat;
}

From source file:com.bitsofproof.example.Simple.java

public static String printBit(long n) {
    BigDecimal xbt = BigDecimal.valueOf(n).divide(BigDecimal.valueOf(100));
    return NumberFormat.getNumberInstance().format(xbt) + " bit";
}

From source file:com.bitsofproof.example.Simple.java

public static long parseBit(String s) throws ParseException {
    Number n = NumberFormat.getNumberInstance().parse(s);
    if (n instanceof Double) {
        return (long) (n.doubleValue() * 100.0);
    } else {/*from ww w . ja v a2s . c o  m*/
        return n.longValue() * 100;
    }
}

From source file:org.kalypso.ogc.sensor.timeseries.TimeseriesUtils.java

private static synchronized NumberFormat getDefaultFormat() {
    if (DEFAULT_FORMAT == null) {
        DEFAULT_FORMAT = NumberFormat.getNumberInstance();
        DEFAULT_FORMAT.setMinimumFractionDigits(3);
    }//from   w w  w. j av a 2  s.  c o m

    return DEFAULT_FORMAT;
}