Example usage for java.text NumberFormat setMaximumFractionDigits

List of usage examples for java.text NumberFormat setMaximumFractionDigits

Introduction

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

Prototype

public void setMaximumFractionDigits(int newValue) 

Source Link

Document

Sets the maximum number of digits allowed in the fraction portion of a number.

Usage

From source file:com.salesmanager.core.module.impl.application.currencies.EURCurrencyModule.java

public String getMeasure(BigDecimal measure, String currencycode) throws Exception {

    NumberFormat nf = null;

    nf = NumberFormat.getInstance(Locale.GERMAN);

    nf.setMaximumFractionDigits(1);
    nf.setMinimumFractionDigits(1);//from ww w  .  ja  v a  2s .co m

    measure.setScale(1, BigDecimal.ROUND_HALF_UP);

    return nf.format(measure);
}

From source file:de.tor.tribes.util.bb.PointStatsFormatter.java

private String[] getStatSpecificReplacements(Stats pStats) {
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumFractionDigits(0);//w w  w  . j a  v  a  2  s. c o m
    nf.setMaximumFractionDigits(0);
    String tribe = pStats.getParent().getTribe().toBBCode();
    String pointsBefore = nf.format(pStats.getPointStart());
    String pointsAfter = nf.format(pStats.getPointEnd());
    String pointsDiff = nf.format(pStats.getPointDiff());

    if (pStats.getPointDiff() > 0) {
        pointsDiff = "[color=green]" + pointsDiff + "[/color]";
    } else {
        pointsDiff = "[color=red]" + pointsDiff + "[/color]";
    }

    double perc = pStats.getExpansion();
    String percentDiff = ((perc >= 0) ? "+" : "") + nf.format(perc) + "%";

    if (perc > 0) {
        percentDiff = "[color=green]" + percentDiff + "[/color]";
    } else {
        percentDiff = "[color=red]" + percentDiff + "[/color]";
    }

    String killsPerPoints = nf.format(pStats.getKillPerPoint());

    return new String[] { tribe, pointsBefore, pointsAfter, pointsDiff, percentDiff, killsPerPoints };
}

From source file:Main.java

private JFormattedTextField setFormat(JFormattedTextField jft, Locale local1, int minFra, int maxFra) {
    NumberFormat numberFormat;
    Locale local = local1;/*  w ww. jav a 2 s.  co  m*/
    int setMin = minFra;
    int setMax = maxFra;
    numberFormat = NumberFormat.getCurrencyInstance(local);
    numberFormat.setMinimumFractionDigits(setMin);
    numberFormat.setMaximumFractionDigits(setMax);
    numberFormat.setRoundingMode(RoundingMode.HALF_UP);
    jft = new JFormattedTextField(numberFormat);
    jft.setValue(new Double(342.796));
    return jft;
}

From source file:com.expressui.core.view.field.format.DefaultFormats.java

/**
 * Gets number format, NumberFormat.getNumberInstance(), using current user's locale.
 *
 * @param maximumFractionDigits maximum number of fraction digits
 * @param defaultValueWhenEmpty when parsing Strings, returns this value when String is empty
 * @return default number format/* w ww .  j a v  a2s  . co m*/
 */
public PropertyFormatter getNumberFormat(int maximumFractionDigits, Object defaultValueWhenEmpty) {
    NumberFormat numberFormat = NumberFormat.getNumberInstance(MainApplication.getInstance().getLocale());
    numberFormat.setMaximumFractionDigits(maximumFractionDigits);
    return new JDKBridgePropertyFormatter(numberFormat, defaultValueWhenEmpty);
}

From source file:io.pcp.parfait.benchmark.StandardMetricThroughPutBenchmark.java

private void report(boolean startPcp, List<MonitoredCounter> counters, long timeTaken,
        List<CounterIncrementer> counterIncrementers) {
    long totalBlockedCount = computeTotalBlockedCount(
            transformToListOfBlockedMetricCollectors(counterIncrementers));
    long totalBlockedTime = computeTotalBlockedTime(
            transformToListOfBlockedMetricCollectors(counterIncrementers));
    double counterIncrements = computeTotalCounterIncrements(counters);

    double incrementRate = counterIncrements / ((double) timeTaken / 1000);
    NumberFormat numberFormat = NumberFormat.getNumberInstance();
    numberFormat.setGroupingUsed(true);//from   ww w . ja v a2s  .c  o  m
    numberFormat.setMaximumFractionDigits(2);
    numberFormat.setMinimumFractionDigits(2);
    String incrementRateString = StringUtils.leftPad(numberFormat.format(incrementRate), 15);

    System.out.printf(
            "pcpStarted: %s\tperMetricLock: %s\tincrementRate(/sec): %s\t blockedCount: %d\t blockedTime: %d\n",
            startPcp, usePerMetricLock, incrementRateString, totalBlockedCount, totalBlockedTime);
}

From source file:edu.monash.merc.struts2.action.TLSumChartAction.java

@SuppressWarnings("unchecked")
public String piechart() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Green", l4);
    dataset.setValue("Yellow", l3);
    dataset.setValue("Red", l2);
    dataset.setValue("Black", l1);

    chart = ChartFactory.createPieChart(dt, dataset, true, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();

    plot.setBackgroundPaint(Color.WHITE);
    //no border/* ww  w .java  2s  .  c  o  m*/
    plot.setOutlineStroke(null);
    //no label
    plot.setLabelGenerator(null);

    NumberFormat percentFormat = NumberFormat.getPercentInstance();
    percentFormat.setMaximumFractionDigits(2);
    plot.setLegendLabelGenerator(
            new StandardPieSectionLabelGenerator("{0}={2}", NumberFormat.getNumberInstance(), percentFormat));
    //set specific colors  green, yellow, red and black
    Color[] colors = { new Color(0, 140, 0), new Color(254, 172, 0), new Color(226, 0, 40),
            new Color(0, 0, 0) };
    setColor(plot, dataset, colors);

    chart.setBackgroundPaint(Color.WHITE);
    chart.getTitle().setFont(chart.getTitle().getFont().deriveFont(11.0f));
    return SUCCESS;
}

From source file:uk.ac.gda.dls.client.views.MonitorCompositeFactory.java

void setVal(String newVal) {
    if (decimalPlaces != null) {
        Scanner sc = new Scanner(newVal.trim());
        if (sc.hasNextDouble()) {
            NumberFormat format = NumberFormat.getInstance();
            format.setMaximumFractionDigits(decimalPlaces.intValue());
            newVal = format.format(sc.nextDouble());
        }//from   www . java  2s. c  o  m
        sc.close();
    }
    val = newVal;
    if (!isDisposed())
        display.asyncExec(setTextRunnable);
}

From source file:org.netxilia.functions.TextFunctions.java

public String FIXED(double number, int decimals, boolean no_thousands_separator) {
    NumberFormat format = NumberFormat.getInstance();
    format.setMaximumFractionDigits(decimals);
    format.setGroupingUsed(!no_thousands_separator);
    return format.format(number);
}

From source file:assign3.client.WaypointClient.java

public void actionPerformed(ActionEvent e) {
    try {/*  w w w .ja v  a2s  .  c o m*/
        if (e.getActionCommand().equals("Remove")) {
            debug("you clicked Remove Waypoint");
            frWps.removeItem(frWps.getSelectedItem());
            toWps.removeItem(toWps.getSelectedItem());
        } else if (e.getActionCommand().equals("Add")) {
            debug("you clicked Add Waypoint");
            addWaypoint();
            distBearIn.setText("Added: " + nameIn.getText());
        } else if (e.getActionCommand().equals("Modify")) {
            debug("you clicked Modify Waypoint");
        } else if (e.getActionCommand().equals("GetLatLon")) {
            debug("you clicked Get Lat/Lon");
        } else if (e.getActionCommand().equals("exportToJSON")) {
            debug("you clicked export to JSON");
            String[] names = server.getNames(); //Check this
            JSONObject obj = new JSONObject();
            for (int i = 0; i < names.length; i++) {
                Waypoint wp = server.get(names[i]);
                obj.put(names[i], wp.toJson());
            }
        } else if (e.getActionCommand().equals("Distance")) {
            debug("you clicked Distance and Bearing");
            String wpFrom = frWps.getSelectedItem().toString();
            String wpTo = toWps.getSelectedItem().toString();
            NumberFormat nf = NumberFormat.getInstance();
            nf.setMaximumFractionDigits(4);
            String distCalc = nf.format(server.distGC(wpFrom, wpTo));
            String dirCalc = nf.format(server.directionGC(wpFrom, wpTo));
            server.distGC(frWps.getName(), toWps.getName());
            server.directionGC(frWps.getName(), toWps.getName());
            distBearIn.setText("Distance from " + wpFrom + " to " + wpTo + " is " + distCalc
                    + " miles, bearing " + dirCalc + ".");
        }
    } catch (RemoteException ex) {
        System.out.println("Server connection error.");
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}

From source file:org.netxilia.functions.TextFunctions.java

public String DOLLAR(double value, int decimals) {
    NumberFormat format = NumberFormat.getCurrencyInstance();
    format.setMaximumFractionDigits(decimals);
    return format.format(value);
}