Example usage for java.math BigDecimal toPlainString

List of usage examples for java.math BigDecimal toPlainString

Introduction

In this page you can find the example usage for java.math BigDecimal toPlainString.

Prototype

public String toPlainString() 

Source Link

Document

Returns a string representation of this BigDecimal without an exponent field.

Usage

From source file:Main.java

public static void main(String[] args) {
    MathContext mc = new MathContext(3); // 3 precision

    BigDecimal bg = new BigDecimal("1234E+4", mc);

    System.out.println("Plain string value of " + bg + " is " + bg.toPlainString());
}

From source file:Main.java

public static String convertToNormal(String str) {
    BigDecimal db = new BigDecimal(str);
    return db.toPlainString();
}

From source file:Main.java

public static String doubleParseToString(double d1) {
    Double d = new Double(d1);
    BigDecimal bd = new BigDecimal(d.toString());
    return bd.toPlainString();
}

From source file:Main.java

public static String[] mapToStringArray(Map<String, Object> map, String... keys) {
    String[] array = new String[keys.length];
    for (int i = 0; i < keys.length; i++) {
        String key = keys[i];/*from  ww  w.j  ava2 s .  c  o m*/
        Object value = map.get(key);
        String strValue = null;
        if (!map.containsKey(key)) {
            strValue = key;
        } else if (value == null) {
            strValue = "";
        } else if (value instanceof BigDecimal) {
            BigDecimal conv = (BigDecimal) value;
            strValue = conv.toPlainString();
        } else {
            strValue = value.toString();
        }
        array[i] = strValue;
    }
    return array;
}

From source file:Main.java

/**
 * Get the given value in satoshis as a string on the form "10.12345000".
 * <p>//from   w  w w . j  a  v a  2s.c  om
 * This method always returns a string with 8 decimal points. If you only
 * wish to have the necessary digits use {@link CoinUtil#valueString(long)}
 * 
 * @param value
 *           The number of satoshis
 * @return The given value in satoshis as a string on the form "10.12345000".
 */
public static String fullValueString(long value) {
    BigDecimal d = BigDecimal.valueOf(value);
    d = d.movePointLeft(8);
    return d.toPlainString();
}

From source file:Main.java

/**
 * Get the given value in satoshis as a string on the form "10.12345".
 * <p>// w w  w. j a  v a2s  .  c o m
 * This method only returns necessary decimal points to tell the exact value.
 * If you wish to have all 8 digits use
 * {@link CoinUtil#fullValueString(long)}
 * 
 * @param value
 *           The number of satoshis
 * @return The given value in satoshis as a string on the form "10.12345".
 */
public static String valueString(long value) {
    BigDecimal d = BigDecimal.valueOf(value);
    d = d.divide(ONE_BTC_IN_SATOSHIS);
    return d.toPlainString();
}

From source file:org.kuali.rice.core.api.criteria.CriteriaKualiPercentValue.java

/**
 * Since KualiPercent is not technically immutable we defensively copy when needed.
 *
 * see Effective Java 2nd ed. page 79 for details.
 *
 * @param val the KualiPercent to check//from   w  w w.  j  a  v  a2  s  . c o m
 * @return the safe BigDecimal
 */
private static BigDecimal safeInstance(BigDecimal val) {
    return new BigDecimal(val.toPlainString());
}

From source file:com.hp.hpl.jena.sparql.util.Utils.java

static public String stringForm(BigDecimal decimal) {
    return decimal.toPlainString();
}

From source file:org.kuali.rice.core.api.criteria.CriteriaDecimalValue.java

/**
 * Since BigDecimal is not technically immutable we defensively copy when needed.
 *
 * see Effective Java 2nd ed. page 79 for details.
 *
 * @param val the big decimal to check/*from  w w w.  j a  v a 2 s .  c  om*/
 * @return the safe BigDecimal
 */
private static BigDecimal safeInstance(BigDecimal val) {
    if (val.getClass() != BigDecimal.class) {
        return new BigDecimal(val.toPlainString());
    }
    return val;
}

From source file:util.POIUtils.java

/**
 * Converts numbers that include exponents into a regular number.
 *
 * @param number original number//  w w  w  . j  a  v  a  2  s .c om
 * @return reformatted number
 **/
private static String formatNumber(double number) {

    String numString = Double.toString(number);
    int idx = numString.indexOf((int) 'E');
    if (idx == -1) {
        // lop off trailing .0
        if (numString.endsWith(".0")) {
            numString = numString.substring(0, numString.length() - 2);
        }
        return numString;
    }

    int exponent = Integer.parseInt(numString.substring(idx + 1));
    int precision = idx - 1;
    if (exponent > 0 && exponent == precision) {
        precision++;
    }
    BigDecimal bd = new BigDecimal(number, new MathContext(precision));
    return bd.toPlainString();
}