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:CurrLocaleServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    //Get the client's Locale
    Locale locale = request.getLocale();
    ResourceBundle bundle = ResourceBundle.getBundle("i18n.WelcomeBundle", locale);
    String welcome = bundle.getString("Welcome");

    NumberFormat nft = NumberFormat.getCurrencyInstance(locale);
    String formatted = nft.format(1000000);

    //Display the locale
    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    out.println("<html><head><title>" + welcome + "</title></head><body>");

    out.println("<h2>" + bundle.getString("Hello") + " " + bundle.getString("and") + " " + welcome + "</h2>");

    out.println("Locale: ");
    out.println(locale.getLanguage() + "_" + locale.getCountry());

    out.println("<br /><br />");
    out.println(formatted);/*  w ww  .ja  va 2 s  .c  o m*/

    out.println("</body></html>");
    out.close();

}

From source file:org.moserp.billing.domain.Bill.java

public String calculateNumber(int billCounter) {
    NumberFormat format = new DecimalFormat("00");
    return saleDate.getYear() + "/" + format.format(saleDate.getMonth().getValue())
            + format.format(billCounter);
}

From source file:com.liferay.portal.events.GarbageCollectorAction.java

public void run(HttpSession ses) throws ActionException {

    try {// w w w.  j av a 2 s  .co  m
        Runtime runtime = Runtime.getRuntime();

        NumberFormat nf = NumberFormat.getInstance();

        _log.debug("Before GC: " + nf.format(runtime.freeMemory()) + " free, "
                + nf.format(runtime.totalMemory()) + " total, and " + nf.format(runtime.maxMemory()) + " max");

        _log.debug("Running garbage collector");

        System.gc();

        _log.debug("After GC: " + nf.format(runtime.freeMemory()) + " free, " + nf.format(runtime.totalMemory())
                + " total, and " + nf.format(runtime.maxMemory()) + " max");
    } catch (Exception e) {
        throw new ActionException(e);
    }
}

From source file:com.deafgoat.ml.prognosticator.UserDefinedAttributeUnitTests.java

@Override
public String getAttributeValue(List<String> instance, Map<String, Integer> attributeMap, ConfigReader cfg) {
    String str3PMTemp = instance.get(attributeMap.get("Temp3pm"));
    String str9AMTemp = instance.get(attributeMap.get("Temp9am"));
    Double diffTemp = Double.parseDouble(str3PMTemp) - Double.parseDouble(str9AMTemp);
    NumberFormat formatter = new DecimalFormat("#0.00");
    return formatter.format(diffTemp);
}

From source file:com.anrisoftware.globalpom.measurement.ValueToString.java

private void formatExactValue(StringBuffer buff, Value value, NumberFormat format) {
    buff.append(format.format(value.getValue()));
    buff.append(SEP);
}

From source file:com.greenpepper.maven.plugin.TestMonitor.java

private String formatElapsedTime(Long runTime) {
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
    return numberFormat.format(runTime.doubleValue() / 1000);
}

From source file:com.haulmont.chile.core.datatypes.impl.DoubleDatatype.java

@Override
public String format(Object value, Locale locale) {
    if (value == null) {
        return "";
    }/* w ww.  j  a v a 2  s .c o m*/

    FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale);
    if (formatStrings == null) {
        return format(value);
    }

    DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols();
    NumberFormat format = new DecimalFormat(formatStrings.getDoubleFormat(), formatSymbols);
    return format.format(value);
}

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

private void report(List<CPUThreadTestRunner> cpuThreadTestRunners, double timeTakenms, int iterations,
        boolean cpuTracingEnabled, CPUThreadTestRunner.CpuLookupMethod cpuLookupMethod) {
    long totalBlockedCount = computeTotalBlockedCount(
            transformToListOfBlockedMetricCollectors(cpuThreadTestRunners));
    long totalBlockedTime = computeTotalBlockedTime(
            transformToListOfBlockedMetricCollectors(cpuThreadTestRunners));

    double iterationsPerSecond = iterations / (timeTakenms / 1000);
    NumberFormat numberInstance = NumberFormat.getNumberInstance();
    String iterationsPerSecondString = numberInstance.format(iterationsPerSecond);

    System.out.printf(/*from   w w w. j a v  a2s . c  o  m*/
            "cpuTracingEnabled: %s\tcpuLookupMethod: %s\titerations/sec: %s\tblockedCount: %d\tblockedTime: %d\n",
            leftPadBoolean(cpuTracingEnabled), formatCpuLookupMethod(cpuLookupMethod),
            iterationsPerSecondString, totalBlockedCount, totalBlockedTime);
}

From source file:com.haulmont.chile.core.datatypes.impl.BigDecimalDatatype.java

@Override
public String format(Object value, Locale locale) {
    if (value == null) {
        return "";
    }/*from   w w w.j a v a 2s.c o  m*/

    FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale);
    if (formatStrings == null) {
        return format(value);
    }

    DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols();
    NumberFormat format = new DecimalFormat(formatStrings.getDecimalFormat(), formatSymbols);
    return format.format(value);
}

From source file:com.eu.evaluation.server.eva.EvaluateExcutorTest.java

@Test
public void test() {
    double d = 0.987;
    logger.info("String.format = " + String.format("%.2f", d));
    DecimalFormat df = new DecimalFormat("*.00");
    logger.info("DecimalFormat = " + df.format(d));

    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(2);//  ww w. j  a va 2 s . c o m
    logger.info("NumberFormat = " + nf.format(d));

    DecimalFormat formater = new DecimalFormat();
    formater.setMaximumFractionDigits(2);
    formater.setGroupingSize(0);
    formater.setRoundingMode(RoundingMode.FLOOR);
    logger.info("DecimalFormat = " + (formater.format(d)));
}