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:org.hyperic.hq.plugin.system.ProcessData.java

public String getFormattedMemPerc() {
    if (_memPerc == Sigar.FIELD_NOTIMPL) {
        return NA;
    }/* w w w .j  av  a  2 s  .  co m*/
    NumberFormat percentFormat = NumberFormat.getPercentInstance();
    percentFormat.setMaximumFractionDigits(1);
    percentFormat.setMinimumFractionDigits(1);
    return percentFormat.format(_memPerc);
}

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

public String getFormatedAmount(BigDecimal amount) throws Exception {
    // TODO Auto-generated method stub
    NumberFormat nf = null;

    Locale locale = Locale.US;

    if (this.decimalPoint == ',') {
        locale = Locale.GERMAN;//from   www  .  ja v a  2 s  .  c o  m
    }

    nf = NumberFormat.getInstance(locale);

    nf.setMaximumFractionDigits(Integer.parseInt(Character.toString(decimalCount)));
    nf.setMinimumFractionDigits(Integer.parseInt(Character.toString(decimalCount)));

    return nf.format(amount);
}

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

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

    NumberFormat nf = null;

    Locale locale = Locale.US;

    if (this.decimalPoint == ',') {
        locale = Locale.GERMAN;//from   w w w.ja  va  2 s  .  co m
    }

    nf = NumberFormat.getInstance(locale);

    nf.setMaximumFractionDigits(1);
    nf.setMinimumFractionDigits(1);

    measure.setScale(1, BigDecimal.ROUND_HALF_UP);

    return nf.format(measure);
}

From source file:me.philnate.textmanager.utils.PDFCreator.java

@SuppressWarnings("deprecation")
private void preparePDF() {
    try {//from w  w  w.  j  a v a2s .  c  o m
        File path = new File(SystemUtils.getUserDir(), "template");
        File template = new File(path, Setting.find("template").getValue());

        Velocity.setProperty("file.resource.loader.path", path.getAbsolutePath());
        Velocity.init();
        VelocityContext ctx = new VelocityContext();

        // User data/Settings
        for (Setting setting : ds.find(Setting.class).asList()) {
            ctx.put(setting.getKey(), setting.getValue());
        }

        NumberFormat format = NumberFormat.getNumberInstance(new Locale(Setting.find("locale").getValue()));
        // #60 always show 2 digits for fraction no matter if right most(s)
        // are zero
        format.setMinimumFractionDigits(2);
        format.setMaximumFractionDigits(2);
        ctx.put("number", format);
        // TODO update schema to have separate first and lastname
        // Customer data
        ctx.put("customer", customer);

        // General data
        ctx.put("month", new DateFormatSymbols().getMonths()[month]);
        ctx.put("math", new MathTool());
        // Billing data
        ctx.put("allItems", BillingItem.find(customer.getId(), year, month));
        ctx.put("billNo", bill.getBillNo());

        StringWriter writer = new StringWriter();
        Velocity.mergeTemplate(template.getName(), ctx, writer);
        File filledTemplate = new File(path, bill.getBillNo() + ".tex");
        FileUtils.writeStringToFile(filledTemplate, writer.toString(), "ISO-8859-1");

        ProcessBuilder pdfLatex = new ProcessBuilder(Setting.find("pdfLatex").getValue(),
                "-interaction nonstopmode", "-output-format pdf", filledTemplate.toString());

        // Saving template file (just in case it may be needed later
        GridFSFile texFile = tex.createFile(filledTemplate);
        texFile.put("month", month);
        texFile.put("year", year);
        texFile.put("customerId", customer.getId());
        texFile.save();

        pdfLatex.directory(path);
        String pdfPath = filledTemplate.toString().replaceAll("tex$", "pdf");
        if (0 == printOutputStream(pdfLatex)) {
            // display Bill in DocumentViewer
            new ProcessBuilder(Setting.find("pdfViewer").getValue(), pdfPath).start().waitFor();
            GridFSFile pdfFile = pdf.createFile(new File(pdfPath));
            pdfFile.put("month", month);
            pdfFile.put("year", year);
            pdfFile.put("customerId", customer.getId());
            pdf.remove(QueryBuilder.start("month").is(month).and("year").is(year).and("customerId")
                    .is(customer.getId()).get());
            pdfFile.save();
            File[] files = path.listFiles((FileFilter) new WildcardFileFilter(bill.getBillNo() + ".*"));
            for (File file : files) {
                FileUtils.forceDelete(file);
            }
        } else {
            new JOptionPane(
                    "Bei der Erstellung der Rechnung ist ein Fehler aufgetreten. Es wurde keine Rechnung erstellt.\n Bitte Schauen sie in die Logdatei fr nhere Fehlerinformationen.",
                    JOptionPane.ERROR_MESSAGE).setVisible(true);
        }
    } catch (IOException e) {
        Throwables.propagate(e);
    } catch (InterruptedException e) {
        Throwables.propagate(e);
    }
}

From source file:gmgen.plugin.PlayerCharacterOutput.java

String getEquipmentList() {
    StringBuilder sb = new StringBuilder();
    boolean firstLine = true;

    for (Equipment eq : pc.getEquipmentListInOutputOrder()) {
        if (!firstLine) {
            sb.append(", ");
        }//from   w ww .j  av a 2 s.c o m

        firstLine = false;

        NumberFormat formater = new DecimalFormat();
        formater.setMaximumFractionDigits(1);
        formater.setMinimumFractionDigits(0);
        sb.append(formater.format(eq.getQty())).append(" ").append(eq.getName());
    }

    return sb.toString();
}

From source file:org.kuali.ext.mm.web.format.MMDecimalFormatter.java

/**
 * Returns a string representation of its argument formatted as a currency value. begin Kuali Foundation modification
 * /* www.  j ava2s .co m*/
 * @see org.kuali.rice.kns.web.format.Formatter#format(java.lang.Object) end Kuali Foundation modification
 */
// begin Kuali Foundation modification
@Override
// end Kuali Foundation modification
public Object format(Object obj) {
    // begin Kuali Foundation modification
    // major code rewrite, original code commented
    /*
     * if (obj == null) return null; NumberFormat formatter = NumberFormat.getCurrencyInstance(); String string = null; try {
     * BigDecimal number = (BigDecimal) obj; number = number.setScale(SCALE, BigDecimal.ROUND_HALF_UP); string =
     * formatter.format(number.doubleValue()); } catch (IllegalArgumentException e) { throw new FormatException(FORMAT_MSG +
     * obj, e); } catch (ClassCastException e) { throw new FormatException(FORMAT_MSG + obj, e); } return showSymbol() ? string :
     * removeSymbol(string);
     */
    LOG.debug("format '" + obj + "'");
    if (obj == null)
        return null;

    NumberFormat formatter = getCurrencyInstanceUsingParseBigDecimal();
    String string = null;

    try {
        Number number;

        if (obj instanceof KualiInteger) {
            formatter.setMaximumFractionDigits(0);
            number = (KualiInteger) obj;

            // Note that treating the number as a MMDecimal below is obsolete. But it doesn't do any harm either since
            // we already set maximumFractionDigits above.
        } else {
            number = (MMDecimal) obj;
            formatter.setMaximumFractionDigits(4);
        }

        // run the incoming MMDecimal's string representation through convertToObject, so that MMDecimal objects
        // containing ill-formatted incoming values will cause the same errors here that ill-formatted Strings do in
        // convertToObject
        MMDecimal convertedNumber = (MMDecimal) convertToObject(number.toString());

        string = formatter.format(convertedNumber.bigDecimalValue());
    } catch (IllegalArgumentException e) {
        throw new FormatException("formatting", RiceKeyConstants.ERROR_CURRENCY, obj.toString(), e);
    } catch (ClassCastException e) {
        throw new FormatException("formatting", RiceKeyConstants.ERROR_CURRENCY, obj.toString(), e);
    }

    return showSymbol() ? string : removeSymbol(string);
    // end Kuali Foundation modification
}

From source file:org.yccheok.jstock.gui.portfolio.AutoDividendJDialog.java

private JFormattedTextField getCurrencyJFormattedTextField() {
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(3);
    NumberFormatter formatter = new NumberFormatter(format);
    formatter.setMinimum(0.0);//from   w w w .j  a v a2s  .  co m
    formatter.setValueClass(Double.class);
    JFormattedTextField formattedTextField = new JFormattedTextField(formatter);
    formattedTextField.addMouseListener(getJFormattedTextFieldMouseListener());
    return formattedTextField;
}

From source file:ubic.gemma.analysis.preprocess.filter.RowLevelFilter.java

/**
 * @param numRows//from w  w  w . ja  v  a  2  s  . c  o  m
 * @param kept
 */
private void logInfo(int numRows, List<CompositeSequence> kept) {
    if (kept.size() == 0) {
        log.warn("All rows filtered out!");
        return;
    }
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(2);

    double fracFiltered = (double) (numRows - kept.size()) / numRows;

    log.info("There are " + kept.size() + " rows left after " + this.method + " filtering. Filtered out "
            + (numRows - kept.size()) + " rows " + nf.format(100 * fracFiltered) + "%");
}

From source file:org.hoteia.qalingo.core.domain.CurrencyReferential.java

public NumberFormat getEcoCurrencyformat() {
    NumberFormat formatter = getStandardCurrencyformat();
    formatter.setGroupingUsed(true);/* w  ww. j a  va 2  s . c  o  m*/
    formatter.setParseIntegerOnly(false);
    formatter.setRoundingMode(RoundingMode.HALF_EVEN);

    formatter.setMaximumFractionDigits(2);
    formatter.setMinimumFractionDigits(2);

    formatter.setMaximumIntegerDigits(1000000);
    formatter.setMinimumIntegerDigits(1);
    return formatter;
}

From source file:com.celements.web.service.CelementsWebScriptService.java

public String getHumanReadableSize(long bytes, boolean si, Locale locale) {
    int unit = si ? 1000 : 1024;
    if (bytes < unit) {
        return bytes + " B";
    }/*from www. j  av a 2 s . c  o m*/
    int exp = (int) (Math.log(bytes) / Math.log(unit));
    String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
    NumberFormat decimalFormat = DecimalFormat.getInstance(locale);
    decimalFormat.setMaximumFractionDigits(1);
    decimalFormat.setMinimumFractionDigits(1);
    return String.format("%s %sB", decimalFormat.format(bytes / Math.pow(unit, exp)), pre);
}