Example usage for java.text NumberFormat format

List of usage examples for java.text NumberFormat format

Introduction

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

Prototype

public final String format(long number) 

Source Link

Document

Specialization of format.

Usage

From source file:mt.LengthDistribution.java

public static void GetLengthDistributionArrayatTime(ArrayList<File> AllMovies, double[] calibration,
        final int framenumber) {

    ArrayList<Double> maxlist = new ArrayList<Double>();
    for (int i = 0; i < AllMovies.size(); ++i) {

        ArrayList<Pair<Integer, Double>> lengthlist = LengthDistribution.LengthdistroatTime(AllMovies.get(i),
                framenumber);//from w  w w. j  ava  2  s.  c o  m

        for (int index = 0; index < lengthlist.size(); ++index) {
            if (lengthlist.get(index).getB() != Double.NaN && lengthlist.get(index).getB() > 0)
                maxlist.add(lengthlist.get(index).getB());

        }
    }
    Collections.sort(maxlist);

    int min = 0;
    int max = 0;
    if (maxlist.size() > 0)
        max = (int) Math.round(maxlist.get(maxlist.size() - 1)) + 1;
    XYSeries counterseries = new XYSeries("MT length distribution");
    XYSeries Logcounterseries = new XYSeries("MT Log length distribution");
    final ArrayList<Point> points = new ArrayList<Point>();
    for (int length = 0; length < max; ++length) {

        HashMap<Integer, Integer> frameseed = new HashMap<Integer, Integer>();

        int count = 0;
        for (int i = 0; i < AllMovies.size(); ++i) {

            File file = AllMovies.get(i);

            ArrayList<FLSobject> currentobject = Tracking.loadMTStat(file);

            if (currentobject != null)
                for (int index = 0; index < currentobject.size(); ++index) {
                    ArrayList<Integer> seedlist = new ArrayList<Integer>();
                    if (currentobject.get(index).length >= length
                            && currentobject.get(index).Framenumber == framenumber) {
                        seedlist.add(currentobject.get(index).seedID);
                        if (frameseed.get(currentobject.get(index).Framenumber) != null
                                && frameseed.get(currentobject.get(index).Framenumber) != Double.NaN) {

                            int currentcount = frameseed.get(currentobject.get(index).Framenumber);
                            frameseed.put(currentobject.get(index).Framenumber, seedlist.size() + currentcount);
                        } else if (currentobject.get(index) != null)
                            frameseed.put(currentobject.get(index).Framenumber, seedlist.size());

                    }

                }

        }

        // Get maxima length, count
        int maxvalue = Integer.MIN_VALUE;

        for (int key : frameseed.keySet()) {

            int Count = frameseed.get(key);

            if (Count >= maxvalue)
                maxvalue = Count;
        }

        if (maxvalue != Integer.MIN_VALUE) {
            counterseries.add(length, maxvalue);

            if (maxvalue > 0) {

                System.out.println("Max " + maxvalue);
                Logcounterseries.add((length), Math.log(maxvalue));
                points.add(new Point(new double[] { length, Math.log(maxvalue) }));
            }

        }
    }

    final XYSeriesCollection dataset = new XYSeriesCollection();
    final XYSeriesCollection nofitdataset = new XYSeriesCollection();
    dataset.addSeries(counterseries);
    nofitdataset.addSeries(counterseries);
    final XYSeriesCollection Logdataset = new XYSeriesCollection();
    Logdataset.addSeries(Logcounterseries);

    final JFreeChart chart = ChartFactory.createScatterPlot("MT length distribution", "Number of MT",
            "Length (micrometer)", dataset);
    final JFreeChart nofitchart = ChartFactory.createScatterPlot("MT length distribution", "Number of MT",
            "Length (micrometer)", nofitdataset);
    // Fitting line to log of the length distribution
    interpolation.Polynomial poly = new interpolation.Polynomial(1);
    try {

        poly.fitFunction(points);

    } catch (NotEnoughDataPointsException e) {

    }
    DisplayPoints.display(nofitchart, new Dimension(800, 500));
    dataset.addSeries(Tracking.drawexpFunction(poly, counterseries.getMinX(), counterseries.getMaxX(), 0.5,
            "Exponential fit"));
    NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);
    nf.setMaximumFractionDigits(3);
    TextTitle legendText = new TextTitle("Mean Length" + " : " + nf.format(-1.0 / poly.getCoefficients(1))
            + "  " + "Standard Deviation" + " : " + nf.format(poly.SSE));
    legendText.setPosition(RectangleEdge.RIGHT);

    DisplayPoints.display(chart, new Dimension(800, 500));
    chart.addSubtitle(legendText);

    System.out.println("Series count" + dataset.getSeriesCount());
    final JFreeChart logchart = ChartFactory.createScatterPlot("MT Log length distribution",
            "Length (micrometer)", "Number of MT", Logdataset);
    //     DisplayPoints.display(logchart, new Dimension(800, 500));
    for (int i = 1; i >= 0; --i)
        System.out.println(poly.getCoefficients(i) + "  " + "x" + " X to the power of " + i);

    //  Logdataset.addSeries(Tracking.drawFunction(poly, counterseries.getMinX(), counterseries.getMaxX(), 0.5, "Straight line fit"));
    WriteLengthdistroFile(AllMovies, counterseries, framenumber);
}

From source file:com.sfs.Formatter.java

/**
 * To currency.// w w w . ja v a  2  s.  c  o m
 *
 * @param value the value
 *
 * @return the string
 */
public static String toCurrency(final double value) {
    String currency = "";
    NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(Locale.US);
    currency = currencyFormatter.format(value);
    return currency;
}

From source file:funcoes.funcoes.java

public static String ajustarDinheiroDigitado(Double valor) {

    NumberFormat formato2 = NumberFormat.getCurrencyInstance();

    String retorno = formato2.format(valor);
    return retorno.substring(3, retorno.length());

}

From source file:com.streamsets.datacollector.util.SystemProcessImpl.java

/**
 * @return a unique number which shorts in descending order
 *///w w  w  .j av  a 2s  .  co m
private static String nextId() {
    NumberFormat numberFormat = NumberFormat.getInstance();
    numberFormat.setMinimumIntegerDigits(10);
    numberFormat.setGroupingUsed(false);
    SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd_HH.mm.ss");
    return Utils.format("{}-{}", dateFormat.format(new Date()),
            numberFormat.format(fileCounter.incrementAndGet()));
}

From source file:com.ibuildapp.romanblack.CataloguePlugin.utils.Utils.java

/**
 * compution currency positon//from   w  ww  .  j ava  2  s.co  m
 */
public static String currencyToPosition(String currencyStr, float price) {
    try {
        Locale locale = Locale.getDefault();
        Currency currency = Currency.getInstance(currencyStr);
        java.text.NumberFormat format = java.text.NumberFormat.getCurrencyInstance(locale);
        format.setCurrency(currency);

        return format.format(price);
    } catch (Exception e) {
        return "";
    }
}

From source file:com.cubusmail.mail.util.MessageUtils.java

/**
 * Format the size of a part like message or attachment.
 * /* w  ww. j  a  va2  s  . c  om*/
 * @param size
 * @return
 */
public static String formatPartSize(int size, NumberFormat format) {

    String value = null;
    if (size >= 1024) {
        value = format.format(size / 1024) + " KB";
    } else {
        if (size > 0) {
            value = Integer.toString(size) + " B";
        } else {
            value = "n/a";
        }
    }
    return value;
}

From source file:gov.nasa.ensemble.common.io.FileUtilities.java

public static String bytesString(long totalSpace) {
    double number = totalSpace;
    NumberFormat format = new DecimalFormat("0.00");
    number /= 1024;//w w w . java2 s .c  o  m
    if (number < 1)
        return "< 1kB";
    if (number < 1024)
        return format.format(number) + "kb";
    number /= 1024;
    if (number < 1024)
        return format.format(number) + "MB";
    number /= 1024;
    if (number < 1024)
        return format.format(number) + "GB";
    number /= 1024;
    return format.format(number) + "TB";
}

From source file:funcoes.funcoes.java

public static String paraFormatoDinheiro(Double valor) {

    NumberFormat formato2 = NumberFormat.getInstance();
    //JOptionPane.showMessageDialog(null, valor);
    //JOptionPane.showMessageDialog(null, formato2);
    return formato2.format(valor);

}

From source file:funcoes.funcoes.java

public static String paraFormatoDinheiroRelatorio(Double valor) {

    NumberFormat formato2 = NumberFormat.getCurrencyInstance();
    //JOptionPane.showMessageDialog(null, valor);
    //JOptionPane.showMessageDialog(null, formato2);
    return formato2.format(valor);

}

From source file:com.streak.logging.analysis.AnalysisUtility.java

public static String formatCsvValue(Object fieldValue, String type) {
    NumberFormat nf = createFixedPointFormat();
    // These strings have been interned so == works for comparison
    if ("string" == type) {
        if (fieldValue instanceof Text) {
            return AnalysisUtility.escapeAndQuoteField(((Text) fieldValue).getValue());
        }/* www.  j av a 2 s  .  c  om*/

        return AnalysisUtility.escapeAndQuoteField("" + fieldValue);
    }
    if ("float" == type) {
        return nf.format(fieldValue);
    }
    if ("integer" == type) {
        if (fieldValue instanceof Date) {
            return "" + ((Date) fieldValue).getTime();
        }
    }

    return "" + fieldValue;
}