Search in sources :

Example 21 with NumberFormat

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);
}
Also used : NumberFormat(java.text.NumberFormat)

Example 22 with NumberFormat

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();
}
Also used : NumberFormat(java.text.NumberFormat)

Example 23 with NumberFormat

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);
}
Also used : DecimalFormat(java.text.DecimalFormat) AssertionFailedError(junit.framework.AssertionFailedError) NumberFormat(java.text.NumberFormat) ObjectInputStream(java.io.ObjectInputStream)

Example 24 with NumberFormat

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));
}
Also used : NumberFormat(java.text.NumberFormat)

Example 25 with NumberFormat

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);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) 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