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();
}
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 };
}
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);
}
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);
}
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);
}
Aggregations