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:org.apache.fineract.portfolio.servicecharge.util.ServiceChargeOperationUtils.java

public static String convertMapToHTMLTable(Map<String, List<BigDecimal>> map, StringBuffer appendHTML) {
    StringBuffer sb = new StringBuffer();
    if (null == appendHTML) {
        sb.append("<table table style=\"width:100%\" border=5pt>");
    }//from w  w  w.  ja v  a  2s . c  o  m
    for (String key : map.keySet()) {
        sb.append("<tr>");
        sb.append("<td>");
        sb.append(key);
        sb.append("</td>");
        for (BigDecimal element : map.get(key)) {
            sb.append("<td>");
            if (element != null)
                sb.append(element.toPlainString());
            else
                sb.append(StringUtils.EMPTY);
            sb.append("</td>");
        }
        sb.append("</tr>");

    }
    sb.append("</table>");
    return sb.toString();
}

From source file:org.kalypso.model.hydrology.util.cm.CatchmentHelper.java

/**
 * This function creates a hash from the catchment.<br/>
 * <br/>//w  w w  .  j ava2  s.  com
 * A hash is generated from the catchment. It takes the factors/timeseries into account. An equal combination of
 * factors and timeseries creates the same hash.
 *
 * @param catchment
 *          The catchment.
 * @return The hash.
 */
public static String buildHash(final ICatchment catchment) {
    /* Memory for the single values. */
    final List<String> values = new ArrayList<>();

    /* Build the hash. */
    final IFeatureBindingCollection<IFactorizedTimeseries> factorizedTimeseries = catchment
            .getFactorizedTimeseries();
    for (final IFactorizedTimeseries timeseries : factorizedTimeseries) {
        final BigDecimal factor = timeseries.getFactor();
        final ZmlLink link = timeseries.getTimeseriesLink();
        values.add(String.format(Locale.PRC, "%s_%s", factor.toPlainString(), link.getHref())); //$NON-NLS-1$
    }

    /* Join the values. */
    return StringUtils.join(values.toArray(new String[] {}), ";"); //$NON-NLS-1$
}

From source file:org.zapto.samhippiemiddlepoolchecker.Values.java

static public String valueToString(float value, int scale) {
    BigDecimal decimal = new BigDecimal(value);
    decimal = decimal.setScale(scale, BigDecimal.ROUND_HALF_UP);
    return decimal.toPlainString();
}

From source file:org.opencloudengine.flamingo.mapreduce.util.MathUtils.java

/**
 * BigDecimal? ?   .//w w w .  jav  a 2 s  .com
 *
 * @param bigDecimal Big Decimal
 * @return ?  
 */
public static String toBeforeDecimalPointString(BigDecimal bigDecimal) {
    String value = bigDecimal.toPlainString();
    if (!value.contains(".")) {
        return bigDecimal.toPlainString();
    }
    String[] strings = value.split("\\.");
    return strings[0];
}

From source file:com.streamsets.pipeline.stage.origin.jdbc.CommonSourceConfigBean.java

public static void upgradeRateLimitConfigs(List<Config> configs, String pathToCommonSourceConfigBean,
        int numThreads) {
    final String queryIntervalField = String.format("%s.queryInterval", pathToCommonSourceConfigBean);
    final String queriesPerSecondField = String.format("%s.queriesPerSecond", pathToCommonSourceConfigBean);
    Config queryIntervalConfig = UpgraderUtils.getAndRemoveConfigWithName(configs, queryIntervalField);
    if (queryIntervalConfig == null) {
        throw new IllegalStateException(
                String.format("Did not find %s in configs: %s", queryIntervalField, configs));
    }//from   w w  w  . j  a  v  a2  s.  c o m

    final Object queryIntervalValue = queryIntervalConfig.getValue();

    final BigDecimal queriesPerSecond = getQueriesPerSecondFromInterval(queryIntervalValue, numThreads,
            queriesPerSecondField, queryIntervalField);

    configs.add(new Config(queriesPerSecondField, queriesPerSecond.toPlainString()));
}

From source file:org.castafiore.utils.StringUtil.java

public static String toCurrency(String currency, BigDecimal b) {
    return TwoDp(b.toPlainString()) + " " + currency;
}

From source file:cn.afterturn.easypoi.util.PoiPublicUtil.java

/**
 * double to String //from w w w . j  a v a  2 s  . c o  m
 * @param value
 * @return
 */
public static String doubleToString(Double value) {
    String temp = value.toString();
    if (temp.contains("E")) {
        BigDecimal bigDecimal = new BigDecimal(temp);
        temp = bigDecimal.toPlainString();
    }
    return temp;
}

From source file:utilities.itext.Turnover.java

private static Paragraph createTablesWithDetails(ArrayList<PaymentPosition> data) throws DocumentException {
    Paragraph paragraph = new Paragraph();

    PdfPTable expense = new PdfPTable(2);
    float[] colWidths = { 5f, 1f };
    expense.setWidths(colWidths);//from   www .  ja  va  2 s  .com

    int lastPaymentID = 0;
    for (PaymentPosition pp : data) {
        if (lastPaymentID != pp.getPayment().getId()) {
            //new Payment
            Paragraph p1 = new Paragraph(pp.getPayment().getPayee().getName());
            PdfPCell c1 = new PdfPCell(p1);

            //add next cell with price
            //calc price
            BigDecimal totalPrice = new BigDecimal(BigInteger.ZERO);
            for (PaymentPosition payPos : data) {
                if (payPos.getPayment().getId() == pp.getPayment().getId()) {
                    totalPrice = totalPrice.add(payPos.getTotalPrice());
                }
            }
            Paragraph p2 = new Paragraph(totalPrice.toPlainString());
            PdfPCell c2 = new PdfPCell(p2);

            c1.setBorder(Rectangle.NO_BORDER);
            c1.setBorderWidthTop(0.5f);
            c2.setBorder(Rectangle.NO_BORDER);
            c2.setBorderWidthTop(0.5f);

            expense.addCell(c1);
            expense.addCell(c2);
        }

        //payment position
        Paragraph p1 = new Paragraph("            " + pp.getQuantity() + "x: " + pp.getArticle().getName());
        PdfPCell c1 = new PdfPCell(p1);

        //add next cell with price
        Paragraph p2 = new Paragraph(pp.getTotalPriceAsString());
        PdfPCell c2 = new PdfPCell(p2);

        c1.setBorder(Rectangle.NO_BORDER);
        c2.setBorder(Rectangle.NO_BORDER);

        expense.addCell(c1);
        expense.addCell(c2);

        lastPaymentID = pp.getPayment().getId();
    }

    paragraph.add(expense);

    paragraph.setSpacingBefore(10f);

    return paragraph;
}

From source file:com.fanniemae.ezpie.common.StringUtilities.java

public static String formatAsNumber(double value) {
    BigDecimal valueOf = BigDecimal.valueOf(value);
    BigDecimal integerPart = BigDecimal.valueOf(valueOf.longValue());
    BigDecimal fractional = valueOf.subtract(integerPart);
    String fraction = fractional.toPlainString();
    int indexOfDot = fraction.indexOf('.') + 1;
    String sign = fraction.startsWith("-") ? "-" : "";
    fraction = fraction.length() > indexOfDot ? fraction.substring(indexOfDot) : fraction;
    if (fraction.equals("0")) {
        return MessageFormat.format("{0}{1}", sign, integerPart.toPlainString(), fraction);
    } else {//ww w .  j  av  a 2  s.c  o  m
        return MessageFormat.format("{0}{1}.{2}", sign, integerPart.toPlainString(), fraction);
    }
}

From source file:org.projectforge.common.NumberHelper.java

/**
 * If given string is an number (NumberUtils.isNumber(String)) then it will be converted to a plain string via BigDecimal.toPlainString().
 * Any exponent such as 1E7 will be avoided.
 * @param str/*w ww  .  j  a v a  2s  .  c o m*/
 * @return Converted string if number, otherwise the origin string.
 * @see NumberUtils#isNumber(String)
 * @see NumberUtils#createBigDecimal(String)
 * @see BigDecimal#toPlainString()
 */
public static String toPlainString(final String str) {
    if (NumberUtils.isNumber(str) == true) {
        final BigDecimal bd = NumberUtils.createBigDecimal(str);
        return bd.toPlainString();
    } else {
        return str;
    }
}