Example usage for java.text NumberFormat getPercentInstance

List of usage examples for java.text NumberFormat getPercentInstance

Introduction

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

Prototype

public static final NumberFormat getPercentInstance() 

Source Link

Document

Returns a percentage format for the current default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:Main.java

public static String saveNumberPercent(float number) {
    NumberFormat nt = NumberFormat.getPercentInstance();
    nt.setMinimumFractionDigits(2);//from  w  ww  .j  a  va2  s . c o  m
    return nt.format(number);
}

From source file:Main.java

public static String getMatchingThresholdToString(int value) {
    double p = -value / 12.0;
    NumberFormat nf = NumberFormat.getPercentInstance();
    nf.setMaximumFractionDigits(Math.max(0, (int) Math.ceil(-p) - 2));
    nf.setMinimumIntegerDigits(1);/*from w w w  . j  a  va 2s. c  om*/
    return nf.format(Math.pow(10, p));
}

From source file:Main.java

public static String percent(double p1, double p2) {
    String str;/*  w w  w.  j a va 2 s  .co  m*/
    double p3 = p1 / p2;
    NumberFormat nf = NumberFormat.getPercentInstance();
    nf.setMinimumFractionDigits(2);
    str = nf.format(p3);
    return str;
}

From source file:Main.java

public static String percent2(double p1, double p2) {
    String str;/*from   ww w. j ava 2s  .  c o m*/
    double p3 = p1 / p2;
    NumberFormat nf = NumberFormat.getPercentInstance();
    nf.setMinimumFractionDigits(0);
    str = nf.format(p3);
    return str;
}

From source file:Main.java

private static String formatPercentage(double percentage) {
    return NumberFormat.getPercentInstance().format(percentage);
}

From source file:org.openmrs.util.Format.java

public static String formatPercentage(double pct) {
    return NumberFormat.getPercentInstance().format(pct);
}

From source file:org.openmrs.util.Format.java

public static String formatPercentage(Number pct) {
    if (pct == null) {
        return "";
    } else {/*  w w  w  . j a  va 2s .  c o m*/
        return NumberFormat.getPercentInstance().format(pct.doubleValue());
    }
}

From source file:Main.java

private static JSpinner makeDigitsOnlySpinnerUsingDocumentFilter() {
    JSpinner spinner = new JSpinner(new SpinnerNumberModel());
    JSpinner.NumberEditor jsEditor = (JSpinner.NumberEditor) spinner.getEditor();
    JFormattedTextField textField = jsEditor.getTextField();
    DocumentFilter digitOnlyFilter = new DocumentFilter() {
        @Override/*from www .  jav  a  2 s  . c  o  m*/
        public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr)
                throws BadLocationException {
            if (stringContainsOnlyDigits(string)) {
                super.insertString(fb, offset, string, attr);
            }
        }

        @Override
        public void remove(FilterBypass fb, int offset, int length) throws BadLocationException {
            super.remove(fb, offset, length);
        }

        @Override
        public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs)
                throws BadLocationException {
            if (stringContainsOnlyDigits(text)) {
                super.replace(fb, offset, length, text, attrs);
            }
        }

        private boolean stringContainsOnlyDigits(String text) {
            for (int i = 0; i < text.length(); i++) {
                if (!Character.isDigit(text.charAt(i))) {
                    return false;
                }
            }
            return true;
        }
    };

    NumberFormat format = NumberFormat.getPercentInstance();
    format.setGroupingUsed(false);
    format.setGroupingUsed(true);
    format.setMaximumIntegerDigits(10);
    format.setMaximumFractionDigits(2);
    format.setMinimumFractionDigits(5);
    textField.setFormatterFactory(new DefaultFormatterFactory(new InternationalFormatter(format) {
        @Override
        protected DocumentFilter getDocumentFilter() {
            return digitOnlyFilter;
        }
    }));
    return spinner;
}

From source file:org.jfree.chart.demo.ParetoChartDemo1.java

public static JFreeChart createChart(CategoryDataset acategorydataset[]) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Freshmeat Software Projects", "Language", "Projects",
            acategorydataset[0], PlotOrientation.VERTICAL, true, true, false);
    jfreechart.addSubtitle(new TextTitle("By Programming Language"));
    jfreechart.addSubtitle(new TextTitle("As at 5 March 2003"));
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setLowerMargin(0.02D);//from   w  w w .  j  a v  a 2s  .  c o  m
    categoryaxis.setUpperMargin(0.02D);
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer();
    NumberAxis numberaxis1 = new NumberAxis("Percent");
    numberaxis1.setNumberFormatOverride(NumberFormat.getPercentInstance());
    categoryplot.setRangeAxis(1, numberaxis1);
    categoryplot.setDataset(1, acategorydataset[1]);
    categoryplot.setRenderer(1, lineandshaperenderer);
    categoryplot.mapDatasetToRangeAxis(1, 1);
    categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    return jfreechart;
}

From source file:hu.sztaki.lpds.portal.util.stream.FileUploadProgressListener.java

/**
 * Getting the upload status/*  w  ww  .  j av a  2  s.  c  om*/
 * @return
 */
public String getFileuploadstatus() {
    // per looks like 0% - 100%, remove % before submission
    String per = NumberFormat.getPercentInstance().format((double) bytesTransferred / (double) fileSize);
    return per.substring(0, per.length() - 1);
}