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:fakingXmocking.CurrencyConversionTest.java

@Test
public void convertFromOneCurrencyToAnother() throws Exception {
    new CurrencySymbolsExpectations();

    // Why strict expectations? To verify the requirement that a live Web site gets accessed.
    new Expectations() {
        {//from   w  ww .  ja v  a 2 s.  c o  m
            httpEntity.getContent();
            result = "<div id=\"converter_results\"><ul><li><b>1 X = 1.3 Y</b>";
        }
    };

    BigDecimal rate = CurrencyConversion.convertFromTo("X", "Y");

    assertEquals("1.3", rate.toPlainString());
}

From source file:au.org.ala.delta.model.attribute.SignificantFiguresAttributeChunkFormatter.java

/**
 * Overrides formatNumber in the parent class to format the number to 5 significant figures.  Trailing
 * zeros are stripped./*ww  w  . j a  v a2 s  .co m*/
 * Note: for compatibility with the original CONFOR significant figures are only applied to values after
 * the decimal place. (e.g. 123456.7 will be formatted as 123456, not 123460)
 * @param number the number to format.
 * @return the supplied number as a String.
 */
@Override
public String formatNumber(BigDecimal number) {

    int significantFigures = determinePrecision(number);
    MathContext context = new MathContext(significantFigures, RoundingMode.HALF_UP);

    BigDecimal result = number.round(context);
    result = result.stripTrailingZeros();
    return result.toPlainString();
}

From source file:org.mjunx.LoggerLoadTester.java

@Override
public void run(String... args) throws Exception {
    final Logger logger = LogManager.getLogger();
    final long start = System.nanoTime();
    for (int i = 0; i < ITERATIONS; i++) {
        logger.info("Test log message #{}", i);
    }//from w w w .  j a  va2 s  . c  o  m
    final long duration = System.nanoTime() - start;
    final BigDecimal average = BigDecimal.valueOf(duration).divide(BigDecimal.valueOf(ITERATIONS));
    System.out.append("Average time per operation: ").append(average.toPlainString()).append(" ns.\n");
}

From source file:com.jive.myco.seyren.core.util.math.BigDecimalSerializer.java

@Override
public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider provider)
        throws IOException, JsonProcessingException {
    if (value != null) {
        gen.writeString(value.toPlainString());
    }// w  w  w . j  a  v  a 2  s  . c om
}

From source file:org.openhab.binding.homematic.internal.converter.state.AbstractTypeConverter.java

/**
 * Rounds a double value.//from  w w w  . j a v a2 s .c o  m
 */
protected BigDecimal round(Double number) {
    BigDecimal bd = new BigDecimal(number == null ? "0" : number.toString());
    String stringBd = bd.toPlainString();
    int scale = stringBd.length() - (stringBd.lastIndexOf('.') + 1);
    return bd.setScale(scale > 2 ? 6 : 2, RoundingMode.HALF_UP);
}

From source file:org.restcomm.sbc.rest.converter.UsageConverter.java

private void writeRate(final BigDecimal rate, final JsonObject object) {
    object.addProperty("rate", rate.toPlainString());
}

From source file:org.restcomm.sbc.rest.converter.UsageConverter.java

private void writeUsage(final BigDecimal usage, final JsonObject object) {
    object.addProperty("usage", usage.toPlainString());
}

From source file:com.aoindustries.website.clientarea.accounting.MakePaymentNewCardAction.java

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response, SiteSettings siteSettings, Locale locale, Skin skin,
        AOServConnector aoConn) throws Exception {
    MakePaymentNewCardForm makePaymentNewCardForm = (MakePaymentNewCardForm) form;

    String accounting = makePaymentNewCardForm.getAccounting();
    if (GenericValidator.isBlankOrNull(accounting)) {
        // Redirect back to credit-card-manager it no accounting selected
        return mapping.findForward("make-payment");
    }/*w  w w .j  av  a 2  s.  c om*/

    // Populate the initial details from the selected accounting code or authenticated user
    Business business = aoConn.getBusinesses().get(AccountingCode.valueOf(accounting));
    if (business == null)
        throw new SQLException("Unable to find Business: " + accounting);
    BusinessProfile profile = business.getBusinessProfile();
    if (profile != null) {
        makePaymentNewCardForm
                .setFirstName(AddCreditCardAction.getFirstName(profile.getBillingContact(), locale));
        makePaymentNewCardForm
                .setLastName(AddCreditCardAction.getLastName(profile.getBillingContact(), locale));
        makePaymentNewCardForm.setCompanyName(profile.getName());
        makePaymentNewCardForm.setStreetAddress1(profile.getAddress1());
        makePaymentNewCardForm.setStreetAddress2(profile.getAddress2());
        makePaymentNewCardForm.setCity(profile.getCity());
        makePaymentNewCardForm.setState(profile.getState());
        makePaymentNewCardForm.setPostalCode(profile.getZIP());
        makePaymentNewCardForm.setCountryCode(profile.getCountry().getCode());
    } else {
        BusinessAdministrator thisBA = aoConn.getThisBusinessAdministrator();
        makePaymentNewCardForm.setFirstName(AddCreditCardAction.getFirstName(thisBA.getName(), locale));
        makePaymentNewCardForm.setLastName(AddCreditCardAction.getLastName(thisBA.getName(), locale));
        makePaymentNewCardForm.setStreetAddress1(thisBA.getAddress1());
        makePaymentNewCardForm.setStreetAddress2(thisBA.getAddress2());
        makePaymentNewCardForm.setCity(thisBA.getCity());
        makePaymentNewCardForm.setState(thisBA.getState());
        makePaymentNewCardForm.setPostalCode(thisBA.getZIP());
        makePaymentNewCardForm.setCountryCode(thisBA.getCountry() == null ? "" : thisBA.getCountry().getCode());
    }

    initRequestAttributes(request, getServlet().getServletContext());

    // Prompt for amount of payment defaults to current balance.
    BigDecimal balance = business.getAccountBalance();
    if (balance.signum() > 0) {
        makePaymentNewCardForm.setPaymentAmount(balance.toPlainString());
    } else {
        makePaymentNewCardForm.setPaymentAmount("");
    }

    request.setAttribute("business", business);

    return mapping.findForward("success");
}

From source file:org.obm.push.bean.Device.java

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    databaseId = (Integer) in.readObject();
    devId = (DeviceId) in.readObject();//  ww  w .j a va 2 s  .  com
    devType = (String) in.readObject();
    hints = (Properties) in.readObject();
    BigDecimal protocolVersionDecimal = (BigDecimal) in.readObject();
    protocolVersion = ProtocolVersion.fromSpecificationValue(protocolVersionDecimal.toPlainString());
}

From source file:org.apache.fineract.portfolio.servicecharge.data.ServiceChargeFinalSheetData.java

private void populateTableRowsWithEntriesinResultsMap(int start, int end, boolean endTable) {
    StringBuffer result = getResultDataAsHTMLTableString();
    for (int iCounter = start; iCounter <= end; iCounter++) {
        ServiceChargeReportTableHeaders header = ServiceChargeReportTableHeaders.fromInt(iCounter);
        List<BigDecimal> dataList = resultsDataMap.get(header);
        if (dataList != null) {
            result.append("<tr>");
            result.append("<td>");
            result.append(header.getCode());
            result.append("</td>");
            for (BigDecimal element : dataList) {
                result.append("<td>");
                if (element != null)
                    result.append(element.toPlainString());
                else
                    result.append(StringUtils.EMPTY);
                result.append("</td>");
            }/*from  w w  w.  j  a v  a2  s.  c om*/
            result.append("</tr>");
        }
    }
    if (endTable) {
        result.append("</table>");
    }
}