Example usage for java.math BigDecimal toEngineeringString

List of usage examples for java.math BigDecimal toEngineeringString

Introduction

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

Prototype

public String toEngineeringString() 

Source Link

Document

Returns a string representation of this BigDecimal , using engineering notation if an exponent is needed.

Usage

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg = new BigDecimal("1E+4");

    System.out.println("Engineering string value of " + bg + " is " + bg.toEngineeringString());
}

From source file:org.apache.giraph.debugger.mock.FormatHelper.java

/**
 * Generates the line that constructs the given object, which can be
 * an int, boolean, char, byte, short, etc.
 * @param input object to construct in the unit test.
 * @return string generating the line that constructs the given object.
 *//*from  w  w w  .  j av a  2 s  . co  m*/
public String format(Object input) {
    if (input instanceof Boolean || input instanceof Byte || input instanceof Character
            || input instanceof Short || input instanceof Integer) {
        return input.toString();
    } else if (input instanceof Long) {
        return input.toString() + "l";
    } else if (input instanceof Float) {
        return decimalFormat.format(input) + "f";
    } else if (input instanceof Double) {
        double val = ((Double) input).doubleValue();
        if (val == Double.MAX_VALUE) {
            return "Double.MAX_VALUE";
        } else if (val == Double.MIN_VALUE) {
            return "Double.MIN_VALUE";
        } else {
            BigDecimal bd = new BigDecimal(val);
            return bd.toEngineeringString() + "d";
        }
    } else {
        return input.toString();
    }
}

From source file:org.wso2.carbon.appfactory.repository.mgt.service.RepositoryManagementService.java

/**
 * publishing git commit event to cassandra
 *
 * @param applicationKey//from   w  w  w  . j a v a  2s.com
 * @param gitUserName
 * @param branch
 * @param commitMessage
 */
public void notifyPostCommit(String applicationKey, String gitUserName, String branch, String commitMessage) {
    String title = gitUserName.split("@")[0] + " committed code to " + branch;
    try {
        EventNotifier.getInstance().notify(ContinousIntegrationEventBuilderUtil
                .buildPostCommitEvents(applicationKey, gitUserName, title, commitMessage));
        Date date = new java.util.Date();
        BigDecimal timeValue = new BigDecimal(date.getTime());
        JSONObject activity = new JSONObject();
        activity.put("item", "commit");
        activity.put("action", "commit");
        activity.put("timestamp", timeValue.toEngineeringString());
        activity.put("appKey", applicationKey);
        activity.put("appVersion", branch);
        String[] activities = new String[1];
        activities[0] = activity.toString();
        BamDataPublisher.getInstance().publishUserActivityEvents(
                CarbonContext.getThreadLocalCarbonContext().getTenantId(), gitUserName, activities);
    } catch (JSONException e) {
        log.error("Failed to publish commits of user", e);
    } catch (AppFactoryException e) {
        log.error("Failed to publish commits of user", e);
    } catch (AppFactoryEventException exception) {
        log.error("Failed to notify committing code to repository", exception);
    }
}