Example usage for java.text DecimalFormat setMinimumFractionDigits

List of usage examples for java.text DecimalFormat setMinimumFractionDigits

Introduction

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

Prototype

@Override
public void setMinimumFractionDigits(int newValue) 

Source Link

Document

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

Usage

From source file:ai.grakn.graql.internal.util.StringConverter.java

/**
 * @param value a value in the graph// www . java 2 s. c o  m
 * @return the string representation of the value (using quotes if it is already a string)
 */
public static String valueToString(Object value) {
    if (value instanceof String) {
        return quoteString((String) value);
    } else if (value instanceof Double) {
        DecimalFormat df = new DecimalFormat("#", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
        df.setMinimumFractionDigits(1);
        df.setMaximumFractionDigits(12);
        df.setMinimumIntegerDigits(1);
        return df.format(value);
    } else {
        return value.toString();
    }
}

From source file:com.midisheetmusicmemo.ChooseSongActivity.java

public static void logHeap() {
    Double allocated = new Double(Debug.getNativeHeapAllocatedSize()) / new Double((1048576));
    Double available = new Double(Debug.getNativeHeapSize()) / 1048576.0f;
    Double free = new Double(Debug.getNativeHeapFreeSize()) / 1048576.0f;
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(2);/*from ww  w.  ja  va 2s .  co  m*/
    df.setMinimumFractionDigits(2);

    Log.d("blah", "debug. =================================");
    Log.d("blah", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available)
            + "MB (" + df.format(free) + "MB free)");
    Log.d("blah",
            "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory() / 1048576))
                    + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory() / 1048576)) + "MB ("
                    + df.format(new Double(Runtime.getRuntime().freeMemory() / 1048576)) + "MB free)");
    System.gc();
    System.gc();
}

From source file:pl.otros.vfs.browser.table.FileSize.java

private static String format(final long value, final long divider, final String unit) {
    final double result = divider > 1 ? (double) value / (double) divider : (double) value;
    DecimalFormat decimalFormat = new DecimalFormat();
    decimalFormat.setMaximumFractionDigits(1);
    decimalFormat.setMinimumFractionDigits(0);
    decimalFormat.setGroupingUsed(false);
    decimalFormat.setDecimalSeparatorAlwaysShown(false);
    return decimalFormat.format(result) + " " + unit;
}

From source file:org.toobsframework.transformpipeline.xslExtentions.PriceFormatHelper.java

/**
 * Gets a string that represents the input Price formatted into the proper fromate, and converted
 * into the proper timezone.//from   www.  jav  a 2 s.co  m
 *
 * @return Price-only string formatted with given time zone.
 *
 * @exception XMLTransfromerException if parsing problem occurs
 */
public static String getFormattedPrice(String inputPrice, String priceFormat, String language)
        throws XMLTransformerException {
    if ((inputPrice == null) || (inputPrice.trim().length() == 0)) {
        inputPrice = "0";
    }

    Locale locale = new Locale(language.substring(2, 4).toLowerCase(), language.substring(0, 2));
    DecimalFormat priceFormatter = (DecimalFormat) NumberFormat.getNumberInstance(locale);
    priceFormatter.setGroupingUsed(true);
    priceFormatter.setMaximumFractionDigits(2);
    priceFormatter.setMinimumFractionDigits(2);

    priceFormatter.applyPattern(priceFormat);

    return priceFormatter.format(new Double(inputPrice));
}

From source file:StringUtils.java

/**
 * Format a percentage for presentation to the user.
 * @param done the percentage to format (0.0 to 1.0)
 * @param digits the number of digits past the decimal point
 * @return a string representation of the percentage
 *///  www  . java2  s  .c  om
public static String formatPercent(double done, int digits) {
    DecimalFormat percentFormat = new DecimalFormat("0.00%");
    double scale = Math.pow(10.0, digits + 2);
    double rounded = Math.floor(done * scale);
    percentFormat.setDecimalSeparatorAlwaysShown(false);
    percentFormat.setMinimumFractionDigits(digits);
    percentFormat.setMaximumFractionDigits(digits);
    return percentFormat.format(rounded / scale);
}

From source file:com.streamreduce.util.MessageUtils.java

public static String roundAndTruncate(double rawValue, int precision) {
    DecimalFormat df = new DecimalFormat();

    df.setMaximumFractionDigits(precision);
    df.setMinimumFractionDigits(precision);
    df.setMinimumIntegerDigits(1);/*  w w w .j a  v a  2 s.c  o  m*/

    return df.format(rawValue);
}

From source file:com.tinypace.mobistore.util.StringUtil.java

public static String formatMoney(BigDecimal d) {
    DecimalFormat mformat = new DecimalFormat();
    mformat.setMaximumFractionDigits(2);
    mformat.setMinimumFractionDigits(2);
    mformat.setGroupingSize(20);//w w  w.  j  a v  a 2  s. c o m
    return mformat.format(d);
}

From source file:net.sourceforge.atunes.utils.StringUtils.java

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

From source file:org.j2free.jsp.el.StandardExtensions.java

/**
 *
 * @param d/*from  w  w w . j av a  2 s .c o m*/
 * @return
 */
public static String formatPercent(float d) {

    DecimalFormat n = new DecimalFormat();
    n.setMinimumFractionDigits(2);
    n.setMaximumFractionDigits(2);
    return n.format(d);
}

From source file:org.j2free.jsp.el.StandardExtensions.java

/**
 *
 * @param decimal/*w  ww. j  a v a  2s .  co m*/
 * @param min
 * @param max
 * @return
 */
public static String formatDecimal(double decimal, int min, int max) {
    DecimalFormat df = new DecimalFormat();
    df.setMinimumFractionDigits(min);
    df.setMaximumFractionDigits(max);
    return df.format(decimal);
}