Search in sources :

Example 71 with NumberFormat

use of java.text.NumberFormat in project cogtool by cogtool.

the class CogTool method getMemoryUsage.

public static String getMemoryUsage() {
    Runtime rt = Runtime.getRuntime();
    long max = rt.maxMemory();
    long free = rt.freeMemory();
    long total = rt.totalMemory();
    double used = (100.0 * (total - free)) / total;
    NumberFormat fmt = NumberFormat.getInstance();
    fmt.setMinimumIntegerDigits(1);
    fmt.setMinimumFractionDigits(2);
    fmt.setMaximumFractionDigits(2);
    fmt.setGroupingUsed(true);
    StringBuilder result = new StringBuilder(L10N.get("CT.Memory", "Memory usage: "));
    // TODO this is not properly locale sensitive, as it assumes US
    //      conventions for percent format and lists
    result.append(fmt.format(used));
    result.append(L10N.get("CT.PercentOf", "% of "));
    result.append(fmt.format(total / 1000000.0));
    result.append(";  ");
    result.append(fmt.format(max / 1000000.0));
    return result.toString();
}
Also used : NumberFormat(java.text.NumberFormat)

Example 72 with NumberFormat

use of java.text.NumberFormat in project Openfire by igniterealtime.

the class StatsAction method getLowAndHigh.

/**
     * Given a statistic key and a start date, end date and number of datapoints, returns
     * a String[] containing the low and high values (in that order) for the given time period.
     * 
     * @param key the name of the statistic to return high and low values for.
     * @param timePeriod start date, end date and number of data points.
     * @return low and high values for the given time period / number of datapoints
     */
public static String[] getLowAndHigh(String key, long[] timePeriod) {
    MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
    StatsViewer viewer = (StatsViewer) plugin.getModule(StatsViewer.class);
    Statistic.Type type = viewer.getStatistic(key)[0].getStatType();
    double[] lows = viewer.getMin(key, timePeriod[0], timePeriod[1], (int) timePeriod[2]);
    double[] highs = viewer.getMax(key, timePeriod[0], timePeriod[1], (int) timePeriod[2]);
    String low;
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(0);
    if (lows.length > 0) {
        if (type == Statistic.Type.count) {
            double result = 0;
            for (int i = 0; i < lows.length; i++) {
                result += lows[i];
            }
            low = String.valueOf((int) result);
        } else {
            double l = 0;
            for (int i = 0; i < lows.length; i++) {
                if (Double.isNaN(lows[i])) {
                    lows[i] = 0;
                }
                l += lows[i];
            }
            low = format.format(l);
        }
    } else {
        low = String.valueOf(0);
    }
    String high;
    if (highs.length > 0) {
        if (type == Statistic.Type.count) {
            double result = 0;
            for (int i = 0; i < highs.length; i++) {
                result += highs[i];
            }
            high = String.valueOf((int) result);
        } else {
            double h = 0;
            for (int i = 0; i < highs.length; i++) {
                if (Double.isNaN(highs[i])) {
                    highs[i] = 0;
                }
                h += highs[i];
            }
            high = format.format(h);
        }
    } else {
        high = String.valueOf(0);
    }
    return new String[] { low, high };
}
Also used : MonitoringPlugin(org.jivesoftware.openfire.plugin.MonitoringPlugin) Statistic(org.jivesoftware.openfire.stats.Statistic) NumberFormat(java.text.NumberFormat)

Example 73 with NumberFormat

use of java.text.NumberFormat in project head by mifos.

the class Money method toString.

public String toString(Short digitsAfterDecimal) {
    // FIXME string formating based on Accounting rule should be done in
    // MoneyUtil class
    // only string representation of BigDecimal should be returned here
    double doubleValue = amount.doubleValue();
    String format = "%." + digitsAfterDecimal.toString() + "f";
    String formatStr = String.format(Locale.ENGLISH, format, 0.0);
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
    DecimalFormat decimalFormat = null;
    if (numberFormat instanceof DecimalFormat) {
        decimalFormat = ((DecimalFormat) numberFormat);
        decimalFormat.applyPattern(formatStr);
        return decimalFormat.format(doubleValue);
    }
    return numberFormat.format(doubleValue);
}
Also used : DecimalFormat(java.text.DecimalFormat) NumberFormat(java.text.NumberFormat)

Example 74 with NumberFormat

use of java.text.NumberFormat in project android-oss by kickstarter.

the class NumberUtils method flooredPercentage.

@NonNull
public static String flooredPercentage(final float value, @NonNull final Locale locale) {
    final NumberFormat numberFormat = NumberFormat.getPercentInstance(locale);
    numberFormat.setRoundingMode(RoundingMode.DOWN);
    return numberFormat.format(value / 100);
}
Also used : NumberFormat(java.text.NumberFormat) NonNull(android.support.annotation.NonNull)

Example 75 with NumberFormat

use of java.text.NumberFormat in project Openfire by igniterealtime.

the class QueryResult method getRelevanceAsPercentage.

/**
     * Returns the relevance as a percentage (no decimal places) formatted according
     * to the locale passed in.
     *
     * @param locale the locale to use to format the percentage.
     * @return the formatted percentage as a String.
     */
public String getRelevanceAsPercentage(Locale locale) {
    NumberFormat format = DecimalFormat.getPercentInstance(locale);
    format.setMaximumFractionDigits(0);
    return format.format(relevance);
}
Also used : NumberFormat(java.text.NumberFormat)

Aggregations

NumberFormat (java.text.NumberFormat)471 DecimalFormat (java.text.DecimalFormat)92 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)24 BigDecimal (java.math.BigDecimal)23 Locale (java.util.Locale)22 Map (java.util.Map)18 Test (org.junit.Test)17 ParseException (java.text.ParseException)16 DecimalFormatSymbols (java.text.DecimalFormatSymbols)14 JFreeChart (org.jfree.chart.JFreeChart)13 IOException (java.io.IOException)12 ParsePosition (java.text.ParsePosition)12 XYSeries (org.jfree.data.xy.XYSeries)11 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)11 Intent (android.content.Intent)10 PrintWriter (java.io.PrintWriter)9 View (android.view.View)8 TextView (android.widget.TextView)8 Currency (java.util.Currency)8