use of java.text.NumberFormat in project simplefacebook by androidquery.
the class FormatUtility method format.
public static String format(double n, int minDigit, int maxDigit) {
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMinimumFractionDigits(minDigit);
nf.setMaximumFractionDigits(maxDigit);
return nf.format(n);
}
use of java.text.NumberFormat in project grails-core by grails.
the class StopWatch method prettyPrint.
/**
* Return a string with a table describing all tasks performed.
* For custom reporting, call getTaskInfo() and use the task info directly.
*/
public String prettyPrint() {
StringBuilder sb = new StringBuilder(shortSummary());
sb.append('\n');
sb.append("-----------------------------------------\n");
sb.append("ms % Task name\n");
sb.append("-----------------------------------------\n");
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMinimumIntegerDigits(5);
nf.setGroupingUsed(false);
NumberFormat pf = NumberFormat.getPercentInstance();
pf.setMinimumIntegerDigits(3);
pf.setGroupingUsed(false);
for (TaskInfo task : getTaskInfo()) {
sb.append(nf.format(task.getTimeMillis())).append(" ");
sb.append(pf.format(task.getTimeSeconds() / getTotalTimeSeconds())).append(" ");
sb.append(task.getTaskName()).append("\n");
}
return sb.toString();
}
use of java.text.NumberFormat in project j2objc by google.
the class DecimalFormatTest method testSerializationHarmonyRICompatible.
public void testSerializationHarmonyRICompatible() throws Exception {
NumberFormat nf = NumberFormat.getInstance(Locale.FRANCE);
DecimalFormat df = null;
if (!(nf instanceof DecimalFormat)) {
throw new Error("This NumberFormat is not a DecimalFormat");
}
df = (DecimalFormat) nf;
ObjectInputStream oinput = null;
DecimalFormat deserializedDF = null;
try {
oinput = new ObjectInputStream(getClass().getResource("/serialization/org/apache/harmony/tests/java/text/DecimalFormat.ser").openStream());
deserializedDF = (DecimalFormat) oinput.readObject();
} finally {
try {
if (null != oinput) {
oinput.close();
}
} catch (Exception e) {
// ignore
}
}
assertEquals(df.getNegativePrefix(), deserializedDF.getNegativePrefix());
assertEquals(df.getNegativeSuffix(), deserializedDF.getNegativeSuffix());
assertEquals(df.getPositivePrefix(), deserializedDF.getPositivePrefix());
assertEquals(df.getPositiveSuffix(), deserializedDF.getPositiveSuffix());
assertEquals(df.getCurrency(), deserializedDF.getCurrency());
DecimalFormatSymbolsTest.assertDecimalFormatSymbolsRIFrance(deserializedDF.getDecimalFormatSymbols());
assertEquals(df.getGroupingSize(), df.getGroupingSize());
assertEquals(df.getMaximumFractionDigits(), deserializedDF.getMaximumFractionDigits());
assertEquals(df.getMaximumIntegerDigits(), deserializedDF.getMaximumIntegerDigits());
assertEquals(df.getMinimumFractionDigits(), deserializedDF.getMinimumFractionDigits());
assertEquals(df.getMinimumIntegerDigits(), deserializedDF.getMinimumIntegerDigits());
assertEquals(df.getMultiplier(), deserializedDF.getMultiplier());
// Deliberately omitted this assertion. Since different data resource
// will cause the assertion fail.
// assertEquals(df, deserializedDF);
}
use of java.text.NumberFormat in project j2objc by google.
the class NumberFormatTest method test_getMaximumIntegerDigits.
/**
* @tests java.text.NumberFormat#getMaximumIntegerDigits()
*/
public void test_getMaximumIntegerDigits() {
NumberFormat format = NumberFormat.getInstance();
format.setMaximumIntegerDigits(2);
assertEquals("Wrong result", "23", format.format(123));
}
use of java.text.NumberFormat in project j2objc by google.
the class DateFormatTest method test_getNumberFormat.
/**
* @tests java.text.DateFormat#getNumberFormat()
*/
public void test_getNumberFormat() {
DateFormat format = DateFormat.getInstance();
NumberFormat nf1 = format.getNumberFormat();
NumberFormat nf2 = format.getNumberFormat();
assertTrue("NumberFormats not identical", nf1 == nf2);
}
Aggregations