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.bdb.weather.display.summary.TemperatureBinSummaryPlot.java

public TemperatureBinSummaryPlot() {
    plot = new CombinedDomainCategoryPlot();
    JFreeChart chart = new JFreeChart(plot);
    setMaxHeight(10000);/*from w  w w.  java2s.  c om*/
    setMaxWidth(10000);

    NumberAxis countAxis = new NumberAxis("Day Count");
    countAxis.setUpperMargin(.2);
    countPlot.setRangeAxis(countAxis);
    countPlot.setDataset(countDataset);

    BarRenderer r = new BarRenderer();
    r.setBaseItemLabelsVisible(true);
    r.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    r.setSeriesPaint(0, Color.BLUE);
    r.setBasePaint(Color.BLUE);
    countPlot.setRenderer(r);

    NumberAxis durationAxis = new NumberAxis("Duration (Hours)");
    durationAxis.setUpperMargin(.2);
    durationPlot.setRangeAxis(durationAxis);
    durationPlot.setDataset(durationDataset);
    r = new BarRenderer();
    r.setBaseItemLabelsVisible(true);
    NumberFormat format = DecimalFormat.getNumberInstance();
    format.setMaximumFractionDigits(1);
    format.setMinimumFractionDigits(1);
    r.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, format));
    r.setSeriesPaint(0, Color.RED);
    r.setBasePaint(Color.RED);
    durationPlot.setRenderer(r);

    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    plot.add(countPlot);
    plot.add(durationPlot);

    chartViewer = new ChartViewer(chart);
    this.setCenter(chartViewer);
}

From source file:picocash.model.impl.Money.java

@Override
public String toString() {
    double result = (double) value / 100;
    NumberFormat numberFormat = NumberFormat.getNumberInstance();
    numberFormat.setMinimumFractionDigits(2);
    numberFormat.setMaximumFractionDigits(2);
    return numberFormat.format(result);
}

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

/**
 * Gets number format for currency.// ww w.  ja v  a 2 s .  co m
 *
 * @param locale                locale to apply to format, useful for displaying currencies other than
 *                              the standard currency of the user's locale.
 * @param maximumFractionDigits maximum number of fraction digits
 * @return currency property formatter
 */
public PropertyFormatter getCurrencyFormat(Locale locale, int maximumFractionDigits) {
    NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale);
    numberFormat.setMaximumFractionDigits(maximumFractionDigits);
    return new JDKBridgePropertyFormatter(numberFormat);
}

From source file:lineage2.gameserver.handler.admincommands.impl.AdminEditChar.java

/**
 * Method showCharacterList./*from   ww  w .j a  v  a 2 s.co  m*/
 * @param activeChar Player
 * @param player Player
 */
public static void showCharacterList(Player activeChar, Player player) {
    if (player == null) {
        GameObject target = activeChar.getTarget();
        if ((target != null) && target.isPlayer()) {
            player = (Player) target;
        } else {
            return;
        }
    } else {
        activeChar.setTarget(player);
    }
    String clanName = "No Clan";
    if (player.getClan() != null) {
        clanName = player.getClan().getName() + "/" + player.getClan().getLevel();
    }
    NumberFormat df = NumberFormat.getNumberInstance(Locale.ENGLISH);
    df.setMaximumFractionDigits(4);
    df.setMinimumFractionDigits(1);
    NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
    StringBuilder replyMSG = new StringBuilder("<html><body>");
    replyMSG.append("<table width=260><tr>");
    replyMSG.append(
            "<td width=40><button value=\"Main\" action=\"bypass -h admin_admin\" width=40 height=15 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>");
    replyMSG.append("<td width=180><center>Character Selection Menu</center></td>");
    replyMSG.append(
            "<td width=40><button value=\"Back\" action=\"bypass -h admin_show_characters 0\" width=40 height=15 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>");
    replyMSG.append("</tr></table><br>");
    replyMSG.append("<table width=270>");
    replyMSG.append("<tr><td width=100>Account/IP:</td><td>" + player.getAccountName() + "/" + player.getIP()
            + "</td></tr>");
    replyMSG.append("<tr><td width=100>Name/Level:</td><td>" + player.getName() + "/" + player.getLevel()
            + "</td></tr>");
    replyMSG.append(
            "<tr><td width=100>Class/Id:</td><td>" + HtmlUtils.htmlClassName(player.getClassId().getId()) + "/"
                    + player.getClassId().getId() + "</td></tr>");
    replyMSG.append("<tr><td width=100>Clan/Level:</td><td>" + clanName + "</td></tr>");
    replyMSG.append(
            "<tr><td width=100>Exp/Sp:</td><td>" + player.getExp() + "/" + player.getSp() + "</td></tr>");
    replyMSG.append("<tr><td width=100>Cur/Max Hp:</td><td>" + (int) player.getCurrentHp() + "/"
            + player.getMaxHp() + "</td></tr>");
    replyMSG.append("<tr><td width=100>Cur/Max Mp:</td><td>" + (int) player.getCurrentMp() + "/"
            + player.getMaxMp() + "</td></tr>");
    replyMSG.append("<tr><td width=100>Cur/Max Load:</td><td>" + player.getCurrentLoad() + "/"
            + player.getMaxLoad() + "</td></tr>");
    replyMSG.append("<tr><td width=100>Patk/Matk:</td><td>" + player.getPAtk(null) + "/"
            + player.getMAtk(null, null) + "</td></tr>");
    replyMSG.append("<tr><td width=100>Pdef/Mdef:</td><td>" + player.getPDef(null) + "/"
            + player.getMDef(null, null) + "</td></tr>");
    replyMSG.append("<tr><td width=100>PAtkSpd/MAtkSpd:</td><td>" + player.getPAtkSpd() + "/"
            + player.getMAtkSpd() + "</td></tr>");
    replyMSG.append("<tr><td width=100>Acc/Evas:</td><td>" + player.getAccuracy() + "/"
            + player.getEvasionRate(null) + "</td></tr>");
    replyMSG.append("<tr><td width=100>Crit/MCrit:</td><td>" + player.getCriticalHit(null, null) + "/"
            + df.format(player.getMagicCriticalRate(null, null)) + "%</td></tr>");
    replyMSG.append("<tr><td width=100>CritDmg/MCritDmg:</td><td>" + player.getCriticalDmg(null, null) + "/"
            + player.getMagicCriticalDmg(null, null) + "</td></tr>");
    replyMSG.append("<tr><td width=100>Walk/Run:</td><td>" + player.getWalkSpeed() + "/" + player.getRunSpeed()
            + "</td></tr>");
    replyMSG.append("<tr><td width=100>Karma/Fame:</td><td>" + player.getKarma() + "/" + player.getFame()
            + "</td></tr>");
    replyMSG.append("<tr><td width=100>PvP/PK:</td><td>" + player.getPvpKills() + "/" + player.getPkKills()
            + "</td></tr>");
    replyMSG.append("<tr><td width=100>Coordinates:</td><td>" + player.getX() + "," + player.getY() + ","
            + player.getZ() + "</td></tr>");
    replyMSG.append("<tr><td width=100>Direction:</td><td>" + PositionUtils.getDirectionTo(player, activeChar)
            + "</td></tr>");
    replyMSG.append("</table><br>");
    replyMSG.append("<table<tr>");
    replyMSG.append(
            "<td><button value=\"Skills\" action=\"bypass -h admin_show_skills\" width=80 height=15 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>");
    replyMSG.append(
            "<td><button value=\"Effects\" action=\"bypass -h admin_show_effects\" width=80 height=15 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>");
    replyMSG.append(
            "<td><button value=\"Actions\" action=\"bypass -h admin_character_actions\" width=80 height=15 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>");
    replyMSG.append("</tr><tr>");
    replyMSG.append(
            "<td><button value=\"Stats\" action=\"bypass -h admin_edit_character\" width=80 height=15 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>");
    replyMSG.append(
            "<td><button value=\"Exp & Sp\" action=\"bypass -h admin_add_exp_sp_to_character\" width=80 height=15 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>");
    replyMSG.append("<td></td>");
    replyMSG.append("</tr></table></body></html>");
    adminReply.setHtml(replyMSG.toString());
    activeChar.sendPacket(adminReply);
}

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

public String getFormatedAmount(BigDecimal amount) throws Exception {

    NumberFormat nf = null;

    nf = NumberFormat.getInstance(Locale.US);

    nf.setMaximumFractionDigits(2);
    nf.setMinimumFractionDigits(2);//ww w  . j a  v a 2s.c  om

    return nf.format(amount);

}

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

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

    NumberFormat nf = null;

    nf = NumberFormat.getInstance(Locale.US);

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

    measure.setScale(1, BigDecimal.ROUND_HALF_UP);

    return nf.format(measure);

}

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

private String[] getStatSpecificReplacements(Stats pStats) {
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumFractionDigits(0);//from w ww  .jav  a 2 s  .  c  o m
    nf.setMaximumFractionDigits(0);
    String tribe = pStats.getParent().getTribe().toBBCode();
    String killsBefore = nf.format(pStats.getBashDefStart());
    String killsAfter = nf.format(pStats.getBashDefEnd());
    String killsDiff = nf.format(pStats.getBashDefDiff());

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

    long pBefore = pStats.getBashDefStart();
    double perc = 0;
    if (pBefore > 0) {
        perc = (double) 100 * (double) pStats.getBashDefDiff() / (double) pBefore;
    }

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

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

    return new String[] { tribe, killsBefore, killsAfter, killsDiff, percentDiff };
}

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

private String[] getStatSpecificReplacements(Stats pStats) {
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumFractionDigits(0);/*from   w ww  . j a va2s. co m*/
    nf.setMaximumFractionDigits(0);
    String tribe = pStats.getParent().getTribe().toBBCode();
    String killsBefore = nf.format(pStats.getBashOffStart());
    String killsAfter = nf.format(pStats.getBashOffEnd());
    String killsDiff = nf.format(pStats.getBashOffDiff());

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

    long pBefore = pStats.getBashOffStart();
    double perc = 0;
    if (pBefore > 0) {
        perc = (double) 100 * (double) pStats.getBashOffDiff() / (double) pBefore;
    }

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

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

    return new String[] { tribe, killsBefore, killsAfter, killsDiff, percentDiff };
}

From source file:eu.choreos.chart.XYChart.java

private JFreeChart createChart(XYDataset dataset, String chartTitle) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            "Execution size", // domain axis label
            "Range", // range axis label
            dataset, // initial series
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );//from  w  w  w . j  a  v a 2  s . co m

    // set chart background
    chart.setBackgroundPaint(Color.white);

    // set a few custom plot features
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(0xffffe0));
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    // set the plot's axes to display integers
    TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setStandardTickUnits(ticks);
    domain.resizeRange(1.1);
    domain.setLowerBound(0.5);

    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setStandardTickUnits(ticks);
    range.setUpperBound(range.getUpperBound() * 1.1);

    // render shapes and lines
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
    plot.setRenderer(renderer);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    // set the renderer's stroke
    Stroke stroke = new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
    renderer.setBaseOutlineStroke(stroke);

    // label the points
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(2);
    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator(
            StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format);
    renderer.setBaseItemLabelGenerator(generator);
    renderer.setBaseItemLabelsVisible(true);

    return chart;
}

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

public String getFormatedAmount(BigDecimal amount) throws Exception {

    NumberFormat nf = null;

    nf = NumberFormat.getInstance(Locale.GERMAN);

    nf.setMaximumFractionDigits(2);
    nf.setMinimumFractionDigits(2);//from  w  w w.j  a v a 2s  . c om

    return nf.format(amount);

}