Example usage for java.text DecimalFormat DecimalFormat

List of usage examples for java.text DecimalFormat DecimalFormat

Introduction

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

Prototype

public DecimalFormat(String pattern) 

Source Link

Document

Creates a DecimalFormat using the given pattern and the symbols for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:com.wabacus.system.datatype.AbsNumberType.java

protected Number getNumber(String strvalue) {
    if (strvalue == null || strvalue.trim().equals(""))
        strvalue = "0";
    if (this.numberformat != null && !this.numberformat.trim().equals("")) {
        DecimalFormat df = new DecimalFormat(this.numberformat);
        Number n = 0;//from  ww  w .  j a  v a 2  s  .c o m
        try {
            n = df.parse(strvalue.trim());
        } catch (ParseException e) {
            log.error(strvalue + "??" + this.numberformat + "?", e);
            n = 0;
        }
        return n;
    } else {
        return null;
    }
}

From source file:io.hops.hopsworks.common.util.FormatUtils.java

public static String time(Long t) {
    DecimalFormat format = new DecimalFormat("#.#");
    Double time = (double) t / 1000d;
    if (time < m) {
        return format.format(time) + "s";
    }//from ww w  .j  ava 2s  . c  o m
    if (time < h) {
        return format.format(time / m) + "m";
    }
    if (time < d) {
        return format.format(time / h) + "h";
    }
    return format.format(time / d) + "d";
}

From source file:net.ceos.project.poi.annotated.core.CellFormulaHandler.java

/**
 * Apply a generic value to the cell.//from  ww w  .j  a  va2 s.  c  om
 * 
 * @param configCriteria
 *            the {@link XConfigCriteria}
 * @param object
 *            the object
 * @param cell
 *            the {@link Cell} to use
 * @throws NoSuchMethodException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws ElementException
 */
protected static void genericHandler(final XConfigCriteria configCriteria, final Object object, final Cell cell)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ElementException {
    if (configCriteria.getElement().isFormula()) {
        if (!toFormula(configCriteria, cell)) {
            // apply the formula
            CellValueHandler.consumeValue(cell, toExplicitFormula(object, configCriteria.getField()));
        }
    } else {
        // normal manage cell
        if (StringUtils.isNotBlank(configCriteria.getElement().transformMask())) {
            DecimalFormat df = new DecimalFormat(configCriteria.getElement().transformMask());
            CellValueHandler.consumeValue(cell,
                    df.format(configCriteria.getField().get(object)).replace(Constants.COMMA, Constants.DOT));
        } else {
            // apply the value
            CellValueHandler.consumeValue(cell, configCriteria.getField().get(object));
        }
    }
}

From source file:de.unidue.inf.is.ezdl.dlcore.utils.StringUtils.java

/**
 * Returns a double value as a string with a given number of decimal digits.
 * //  w w  w .  j a v a2  s. c  o m
 * @param value
 *            double value
 * @param numberOfDecimals
 *            number of decimal digits
 * @return string with a given number of decimal digits
 */
public static String toString(double value, int numberOfDecimals) {
    DecimalFormat df = new DecimalFormat("#.#");
    df.setMinimumFractionDigits(numberOfDecimals);
    return df.format(value);
}

From source file:com.anrisoftware.globalpom.format.measurement.MeasureFormat.java

/**
 * @see MeasureFormatFactory#create(MeasureFactory, Format)
 *///from w w  w.  ja v  a2 s.  c  o m
@AssistedInject
MeasureFormat(@Assisted MeasureFactory measureFactory, @Assisted Format valueFormat) {
    this(measureFactory, valueFormat, new DecimalFormat("#.#########"));
}

From source file:gr.cti.android.experimentation.service.SqlDbService.java

@PostConstruct
public void init() {
    df = new DecimalFormat("#.000");
}

From source file:com.fatwire.dta.sscrawler.reporting.reporters.PageletTimingsStatisticsReporter.java

@Override
public synchronized void endCollecting() {
    if (pagesDone.get() == 0)
        return;/*w  ww .  ja  v a2  s. c o  m*/
    report.startReport();
    final DecimalFormat df = new DecimalFormat("###0.00");
    final DecimalFormat lf = new DecimalFormat("##0");
    int l = 0;
    for (final String s : stats.keySet()) {
        l = Math.max(s.length(), l);
    }
    l += 3;
    final char[] blank = new char[l];
    Arrays.fill(blank, ' ');
    report.addHeader("pagename" + new String(blank, 0, l - 8), "invocations", "average", "min", "max",
            "standard-deviation");

    for (final Map.Entry<String, SynchronizedSummaryStatistics> e : stats.entrySet()) {
        final SynchronizedSummaryStatistics s = e.getValue();

        final String n = e.getKey() + new String(blank, 0, l - e.getKey().length())
                + (Boolean.FALSE.equals(cached.get(e.getKey())) ? " * " : "   ");

        report.addRow(n, Long.toString(s.getN()), df.format(s.getMean()), lf.format(s.getMin()),
                lf.format(s.getMax()), df.format(s.getStandardDeviation()));

    }
    final String n = "total" + new String(blank, 0, l - "total".length());
    report.addRow(n, Long.toString(total.getN()), df.format(total.getMean()), lf.format(total.getMin()),
            lf.format(total.getMax()), df.format(total.getStandardDeviation()));

    report.finishReport();

}

From source file:com.gym.controller.UsuarioController.java

public Collection<String> cargaPeso() {

    Collection<String> peso = new ArrayList<String>();
    //Collection<Float> peso = new ArrayList<Float>();

    //Float a = 40.0F;
    Double a = 40.0;// ww  w .ja  va  2s. c  om

    DecimalFormat format = new DecimalFormat("0.0");

    //for (a=40.0F; a<140.0F; a=a+0.1F) {
    for (a = 40.0; a < 140; a = a + 0.1) {
        format.format(a);
        peso.add(format.format(a));
    }
    return peso;
}

From source file:TrackerPanel.java

public TrackerPanel() {
    setBackground(Color.GRAY);//from   w ww  .  j  a v a2 s  .c o m

    df = new DecimalFormat("0.#"); // 1 dp
    msgFont = new Font("SansSerif", Font.BOLD, 13);

    configOpenNI();

    histogram = new float[MAX_DEPTH_SIZE];

    imWidth = depthMD.getFullXRes();
    imHeight = depthMD.getFullYRes();
    setSize(imWidth * 2, imHeight);
    System.out.println("Image dimensions (" + imWidth + ", " + imHeight + ")");
    // create empty image bytes array of correct size and type
    imgbytes = new byte[imWidth * imHeight * 3];
    hideBGPixel = new Color(0, 0, 255, 0).getRGB();

    // create d.s for holding camera pixels and image
    cameraPixels = new int[imWidth * imHeight];
    cameraImage = new BufferedImage(imWidth, imHeight, BufferedImage.TYPE_INT_ARGB);
    // the image must have an alpha channel for the transparent blue pixels

    new Thread(this).start(); // start updating the panel
}

From source file:org.geppetto.simulation.CustomSerializer.java

@Override
public void serialize(Double value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonGenerationException {

    if (null == value) {
        // write the word 'null' if there's no value available
        jgen.writeNull();//www  . j  a va2  s  .  com
    } else if (value.equals(Double.NaN)) {
        jgen.writeNumber(Double.NaN);
    } else {
        final String pattern = "#.##";
        final DecimalFormat myFormatter = new DecimalFormat(pattern);
        final String output = myFormatter.format(value).replace(",", ".");
        jgen.writeNumber(output);
    }
}