Example usage for java.text NumberFormat format

List of usage examples for java.text NumberFormat format

Introduction

In this page you can find the example usage for java.text NumberFormat format.

Prototype

public final String format(long number) 

Source Link

Document

Specialization of format.

Usage

From source file:com.attribyte.essem.model.index.IndexStats.java

/**
 * Gets a value as MB./* w  ww  .  j av  a 2s .  co m*/
 * @param val The value.
 * @return The value as MB.
 */
private String asMB(final long val) {
    double valBytes = (double) val;
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMinimumFractionDigits(0);
    nf.setMaximumFractionDigits(0);
    nf.setMinimumIntegerDigits(1);
    return nf.format(valBytes / 1000 / 1000);
}

From source file:io.pcp.parfait.benchmark.StandardMetricThroughPutBenchmark.java

private void report(boolean startPcp, List<MonitoredCounter> counters, long timeTaken,
        List<CounterIncrementer> counterIncrementers) {
    long totalBlockedCount = computeTotalBlockedCount(
            transformToListOfBlockedMetricCollectors(counterIncrementers));
    long totalBlockedTime = computeTotalBlockedTime(
            transformToListOfBlockedMetricCollectors(counterIncrementers));
    double counterIncrements = computeTotalCounterIncrements(counters);

    double incrementRate = counterIncrements / ((double) timeTaken / 1000);
    NumberFormat numberFormat = NumberFormat.getNumberInstance();
    numberFormat.setGroupingUsed(true);//from w w  w.  jav a 2s. co m
    numberFormat.setMaximumFractionDigits(2);
    numberFormat.setMinimumFractionDigits(2);
    String incrementRateString = StringUtils.leftPad(numberFormat.format(incrementRate), 15);

    System.out.printf(
            "pcpStarted: %s\tperMetricLock: %s\tincrementRate(/sec): %s\t blockedCount: %d\t blockedTime: %d\n",
            startPcp, usePerMetricLock, incrementRateString, totalBlockedCount, totalBlockedTime);
}

From source file:com.skilrock.lms.web.scratchService.orderMgmt.common.AgentOrderProcessAction.java

public List<Double> getRetCreditDetails() throws Exception {
    System.out.println("hellllloooooooo");
    PrintWriter out = getResponse().getWriter();
    GameDetailsHelper gameHelper = new GameDetailsHelper();
    List<Double> accountList = null;
    try {//from ww  w .  j  av  a 2  s  .  c  o m
        accountList = gameHelper.fetchAgentRetailerAccDetail(getRetOrgName());
    } catch (LMSException e) {
        System.out.println("In boOrderProcessAction get Credit details");
        e.printStackTrace();
    }
    HttpSession session = getRequest().getSession();
    double creditrLimit = 0.0;
    double currentCrLimit = 0.0;
    double availableLimit = 0.0;
    if (accountList != null) {
        System.out.println("acountlist not null");
        creditrLimit = accountList.get(0);
        currentCrLimit = accountList.get(1);
        availableLimit = accountList.get(2);
        session.setAttribute("RETCRLIMIT", roundTo2DecimalPlaces(currentCrLimit));
        session.setAttribute("RETCURRBAL", roundTo2DecimalPlaces(availableLimit));
        // session.setAttribute("RETAVAILBAL",availableBalance);
    }
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumFractionDigits(2);
    String availableLimitToDisplay = nf.format(availableLimit).replace(",", "");
    String html = "<tr><td><font color='red'>  Order Cannot be Dispatched !   Available Credit Amount of '"
            + getRetOrgName()
            + "' is Insufficient </font> </td><td><br><font color='red'>Available Credit Amount is :</font><input type='text' readonly='true' name='crBal' id='crBal' value='"
            + availableLimitToDisplay + "'/></td></tr>";
    System.out.println(html + "99999999999");
    response.setContentType("text/html");

    out.print(html);
    System.out.println("crredit amount" + currentCrLimit + "avalaible credit" + availableLimit);
    return null;

}

From source file:de.tor.tribes.util.bb.TroopListFormatter.java

@Override
public String formatElements(List<VillageTroopsHolder> pElements, boolean pExtended) {
    StringBuilder b = new StringBuilder();
    int cnt = 1;//  w  ww  .j a v  a  2s  .  c om
    NumberFormat f = getNumberFormatter(pElements.size());
    String beforeList = getHeader();
    String listItemTemplate = getLineTemplate();
    String afterList = getFooter();
    String replacedStart = StringUtils.replaceEach(beforeList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });

    VillageTroopsHolder dummyHolder = new VillageTroopsHolder();
    //replace unit icons
    replacedStart = StringUtils.replaceEach(replacedStart, dummyHolder.getBBVariables(),
            dummyHolder.getReplacements(pExtended));
    b.append(replacedStart).append("\n");
    formatElementsCore(b, pElements, pExtended, listItemTemplate, f);
    String replacedEnd = StringUtils.replaceEach(afterList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedEnd);
    return b.toString();
}

From source file:de.tor.tribes.util.bb.AllyReportStatsFormatter.java

@Override
public String formatElements(List<AllyStatResult> pElements, boolean pExtended) {
    StringBuilder b = new StringBuilder();
    int cnt = 1;/*from   w w w  .ja v a2  s  .  c  o  m*/
    NumberFormat f = getNumberFormatter(pElements.size());
    String beforeList = getHeader();
    String listItemTemplate = getLineTemplate();
    String afterList = getFooter();
    String replacedStart = StringUtils.replaceEach(beforeList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedStart);
    for (AllyStatResult n : pElements) {
        String[] replacements = n.getReplacements(pExtended);
        String itemLine = StringUtils.replaceEach(listItemTemplate, n.getBBVariables(), replacements);
        itemLine = StringUtils.replaceEach(itemLine, new String[] { ELEMENT_ID, ELEMENT_COUNT },
                new String[] { f.format(cnt), f.format(pElements.size()) });
        b.append(itemLine).append("\n");
        cnt++;
    }
    String replacedEnd = StringUtils.replaceEach(afterList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedEnd);
    return b.toString();
}

From source file:de.tor.tribes.util.bb.TribeReportStatsFormatter.java

@Override
public String formatElements(List<TribeStatResult> pElements, boolean pExtended) {
    StringBuilder b = new StringBuilder();
    int cnt = 1;//from   w w  w . ja  va 2  s . c  om
    NumberFormat f = getNumberFormatter(pElements.size());
    String beforeList = getHeader();
    String listItemTemplate = getLineTemplate();
    String afterList = getFooter();
    String replacedStart = StringUtils.replaceEach(beforeList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedStart);
    for (TribeStatResult n : pElements) {
        String[] replacements = n.getReplacements(pExtended);
        String itemLine = StringUtils.replaceEach(listItemTemplate, n.getBBVariables(), replacements);
        itemLine = StringUtils.replaceEach(itemLine, new String[] { ELEMENT_ID, ELEMENT_COUNT },
                new String[] { f.format(cnt), f.format(pElements.size()) });
        b.append(itemLine).append("\n");
        cnt++;
    }
    String replacedEnd = StringUtils.replaceEach(afterList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedEnd);
    return b.toString();
}

From source file:com.talent.aio.examples.im.client.ui.JFrameMain.java

public static void updateConnectionCount() {
    if (isNeedUpdateConnectionCount) {
        isNeedUpdateConnectionCount = false;

        NumberFormat numberFormat = NumberFormat.getInstance();

        ClientGroupContext<Object, ImPacket, Object> clientGroupContext = imClientStarter
                .getClientGroupContext();
        int connectionCount = clientGroupContext.getConnections().size();
        instance.connectionCountLabel.setText("" + numberFormat.format(connectionCount));

        int connectedCount = clientGroupContext.getConnecteds().size();
        instance.connectedCountLabel.setText("" + numberFormat.format(connectedCount));

        int closedCount = clientGroupContext.getCloseds().size();
        instance.closedCountLabel.setText("" + numberFormat.format(closedCount));

        //         log.error("{},{},{}", connectionCount, connectedCount, closedCount);
    }//from w ww  .j a v  a  2  s  .c  om
}

From source file:de.tor.tribes.util.bb.NoteListFormatter.java

@Override
public String formatElements(List<Note> pElements, boolean pExtended) {
    StringBuilder b = new StringBuilder();
    int cnt = 1;/*from www  .  j  a va  2 s  .c o  m*/
    NumberFormat f = getNumberFormatter(pElements.size());
    String beforeList = getHeader();
    String listItemTemplate = getLineTemplate();
    String afterList = getFooter();
    String replacedStart = StringUtils.replaceEach(beforeList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedStart);
    for (Note n : pElements) {
        String[] replacements = n.getReplacements(pExtended);
        String itemLine = StringUtils.replaceEach(listItemTemplate, n.getBBVariables(), replacements);
        itemLine = StringUtils.replaceEach(itemLine, new String[] { ELEMENT_ID, ELEMENT_COUNT },
                new String[] { f.format(cnt), f.format(pElements.size()) });
        b.append(itemLine).append("\n");
        cnt++;
    }
    String replacedEnd = StringUtils.replaceEach(afterList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedEnd);
    return b.toString();
}

From source file:de.tor.tribes.util.bb.ReportListFormatter.java

@Override
public String formatElements(List<FightReport> pElements, boolean pExtended) {
    StringBuilder b = new StringBuilder();
    int cnt = 1;/*from  w w w.  jav a 2s .c  o  m*/
    NumberFormat f = getNumberFormatter(pElements.size());
    String beforeList = getHeader();
    String listItemTemplate = getLineTemplate();
    String afterList = getFooter();
    String replacedStart = StringUtils.replaceEach(beforeList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedStart);
    for (FightReport r : pElements) {
        String[] replacements = r.getReplacements(pExtended);
        String itemLine = StringUtils.replaceEach(listItemTemplate, r.getBBVariables(), replacements);
        itemLine = StringUtils.replaceEach(itemLine, new String[] { ELEMENT_ID, ELEMENT_COUNT },
                new String[] { f.format(cnt), f.format(pElements.size()) });
        b.append(itemLine).append("\n");
        cnt++;
    }
    String replacedEnd = StringUtils.replaceEach(afterList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedEnd);
    return b.toString();
}

From source file:guineu.modules.dataanalysis.PCA.PCADataset.java

public String getYLabel() {
    NumberFormat formatter = new DecimalFormat("#0.00");
    String variation = formatter
            .format((this.mainComponents.get(yAxisPC - 1).eigenValue / this.totalVariation) * 100);
    if (yAxisPC == 1) {
        return "1st PC (" + variation + "%)";
    }//from   ww  w  .  jav  a2s . c  o m
    if (yAxisPC == 2) {
        return "2nd PC (" + variation + "%)";
    }
    if (yAxisPC == 3) {
        return "3rd PC (" + variation + "%)";
    }
    return "" + yAxisPC + "th PC (" + variation + "%)";
}