Java Code Examples for java.text.DecimalFormatSymbols#setExponentSeparator()

The following examples show how to use java.text.DecimalFormatSymbols#setExponentSeparator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DFSSerialization.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private File createTestObject(String objectName, String expString){
    DecimalFormatSymbols dfs= new DecimalFormatSymbols();
    dfs.setExponentSeparator(expString);
    dfs.setCurrencySymbol("*SpecialCurrencySymbol*");
    logln(" The special exponent separator is set : "  + dfs.getExponentSeparator());
    logln(" The special currency symbol is set : "  + dfs.getCurrencySymbol());

    // 6345659: create a test object in the test.class dir where test user has a write permission.
    File file = new File(System.getProperty("test.class", "."), objectName);
    try (FileOutputStream ostream = new FileOutputStream(file)) {
        ObjectOutputStream p = new ObjectOutputStream(ostream);
        p.writeObject(dfs);
        //System.out.println(" The special currency symbol is set : "  + dfs.getCurrencySymbol());
        return file;
    } catch (Exception e){
        errln("Test Malfunction in DFSSerialization: Exception while creating an object");
        /*
         * logically should not throw this exception as errln throws exception
         * if not thrown yet - but in case errln got changed
         */
        throw new RuntimeException("Test Malfunction: re-throwing the exception", e);
    }
}
 
Example 2
Source File: Utils.java    From onpc with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Procedure creates new dot-separated DecimalFormat
 */
public static DecimalFormat getDecimalFormat(String format)
{
    DecimalFormat df = new DecimalFormat(format);
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    dfs.setDecimalSeparator('.');
    dfs.setExponentSeparator("e");
    df.setDecimalFormatSymbols(dfs);
    return df;
}
 
Example 3
Source File: CompatUtils.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Procedure creates new dot-separated DecimalFormat
 */
public static DecimalFormat getDecimalFormat(String format)
{
    DecimalFormat df = new DecimalFormat(format);
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    dfs.setDecimalSeparator('.');
    dfs.setExponentSeparator("e");
    df.setDecimalFormatSymbols(dfs);
    return df;
}
 
Example 4
Source File: DecimalFormatSymbolsTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @tests serialization/deserialization compatibility with RI6.
 */
public void testSerializationCompatibility() throws Exception {
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US);
    symbols.setExponentSeparator("EE");
    symbols.setNaN("NaN");
    SerializationTest.verifyGolden(this, symbols);
}
 
Example 5
Source File: DecimalFormatTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_exponentSeparator() throws Exception {
    DecimalFormat df = new DecimalFormat("0E0");
    assertEquals("1E4", df.format(12345.));

    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
    dfs.setExponentSeparator("-useless-api-");
    df.setDecimalFormatSymbols(dfs);
    assertEquals("1-useless-api-4", df.format(12345.));
}
 
Example 6
Source File: DFSSerialization.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void TestDFSSerialization(){
    /*
     * 1. read from the object created using jdk1.4.2
     */
    File oldFile = new File(System.getProperty("test.src", "."), "DecimalFormatSymbols.142.txt");
    DecimalFormatSymbols dfs142 = readTestObject(oldFile);
    if (dfs142 != null){
        if (dfs142.getExponentSeparator().equals("E") && dfs142.getCurrencySymbol().equals("*SpecialCurrencySymbol*")){
            System.out.println("\n  Deserialization of JDK1.4.2 Object from the current JDK: Passed.");
            logln(" Deserialization of JDK1.4.2 Object from the current JDK: Passed.");
        } else {
            errln(" Deserialization of JDK1.4.2 Object from the current JDK was Failed:"
                  +dfs142.getCurrencySymbol()+" "+dfs142.getExponentSeparator());
            /*
             * logically should not throw this exception as errln throws exception
             * if not thrown yet - but in case errln got changed
             */
            throw new RuntimeException(" Deserialization of JDK1.4.2 Object from the current JDK was Failed:"
                                       +dfs142.getCurrencySymbol()+" "+dfs142.getExponentSeparator());
        }
    }
    /*
     * 2. create a valid DecimalFormatSymbols object with current JDK, then read the object
     */
    String validObject = "DecimalFormatSymbols.current";
    File currentFile = createTestObject(validObject, "*SpecialExponentSeparator*");

    DecimalFormatSymbols dfsValid = readTestObject(currentFile);
    if (dfsValid != null){
        if (dfsValid.getExponentSeparator().equals("*SpecialExponentSeparator*") &&
            dfsValid.getCurrencySymbol().equals("*SpecialCurrencySymbol*")){
            System.out.println("  Deserialization of current JDK Object from the current JDK: Passed.");
            logln(" Deserialization of current JDK Object from the current JDK: Passed.");
        } else {
            errln(" Deserialization of current JDK Object from the current JDK was Failed:"
                  +dfsValid.getCurrencySymbol()+" "+dfsValid.getExponentSeparator());
            /*
             * logically should not throw this exception as errln throws exception
             * if not thrown yet - but in case errln got changed
             */
            throw new RuntimeException(" Deserialization of current Object from the current JDK was Failed:"
                                       +dfsValid.getCurrencySymbol()+" "+dfsValid.getExponentSeparator());
        }
    }
    /*
     * 3. Try to create an valid DecimalFormatSymbols object by passing null
     *    to set null for the exponent separator symbol. Expect the NullPointerException.
     */
    DecimalFormatSymbols symNPE = new DecimalFormatSymbols(Locale.US);
    boolean npePassed = false;
    try {
        symNPE.setExponentSeparator(null);
    } catch (NullPointerException npe){
        npePassed = true;
        System.out.println("  Trying to set exponent separator with null: Passed.");
        logln(" Trying to set exponent separator with null: Passed.");
    }
    if (!npePassed){
        System.out.println(" Trying to set exponent separator with null:Failed.");
        errln("  Trying to set exponent separator with null:Failed.");
        /*
         * logically should not throw this exception as errln throws exception
         * if not thrown yet - but in case errln got changed
         */
        throw new RuntimeException(" Trying to set exponent separator with null:Failed.");
    }

}
 
Example 7
Source File: SakaiDecimalFormatSymbolsProvider.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DecimalFormatSymbols getInstance(final Locale locale) throws IllegalArgumentException, NullPointerException {
	if (locale == null) {
		throw new NullPointerException("locale:null");
	} else if (!SakaiLocaleServiceProviderUtil.isAvailableLocale(locale)) {
		throw new IllegalArgumentException("locale:" + locale.toString());
	}

	DecimalFormatSymbols symbols = new DecimalFormatSymbols();
	symbols.setDecimalSeparator(
			SakaiLocaleServiceProviderUtil.getChar("DecimalSeparator", locale));
	symbols.setDigit(
			SakaiLocaleServiceProviderUtil.getChar("Digit", locale));
	symbols.setExponentSeparator(
			SakaiLocaleServiceProviderUtil.getString("ExponentSeparator", locale));
	symbols.setGroupingSeparator(
			SakaiLocaleServiceProviderUtil.getChar("GroupingSeparator", locale));
	symbols.setInfinity(
			SakaiLocaleServiceProviderUtil.getString("Infinity", locale));
	symbols.setInternationalCurrencySymbol(
			SakaiLocaleServiceProviderUtil.getString("InternationalCurrencySymbol", locale));
	symbols.setCurrencySymbol(
			SakaiLocaleServiceProviderUtil.getString("CurrencySymbol", locale));
	symbols.setMinusSign(
			SakaiLocaleServiceProviderUtil.getChar("MinusSign", locale));
	symbols.setMonetaryDecimalSeparator(
			SakaiLocaleServiceProviderUtil.getChar("MonetaryDecimalSeparator", locale));
	symbols.setNaN(
			SakaiLocaleServiceProviderUtil.getString("NaN", locale));
	symbols.setPatternSeparator(
			SakaiLocaleServiceProviderUtil.getChar("PatternSeparator", locale));
	symbols.setPercent(
			SakaiLocaleServiceProviderUtil.getChar("Percent", locale));
	symbols.setPerMill(
			SakaiLocaleServiceProviderUtil.getChar("PerMill", locale));
	symbols.setZeroDigit(
			SakaiLocaleServiceProviderUtil.getChar("ZeroDigit", locale));

	return symbols;
}
 
Example 8
Source File: SakaiDecimalFormatSymbolsProvider.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DecimalFormatSymbols getInstance(final Locale locale) throws IllegalArgumentException, NullPointerException {
	if (locale == null) {
		throw new NullPointerException("locale:null");
	} else if (!SakaiLocaleServiceProviderUtil.isAvailableLocale(locale)) {
		throw new IllegalArgumentException("locale:" + locale.toString());
	}

	DecimalFormatSymbols symbols = new DecimalFormatSymbols();
	symbols.setDecimalSeparator(
			SakaiLocaleServiceProviderUtil.getChar("DecimalSeparator", locale));
	symbols.setDigit(
			SakaiLocaleServiceProviderUtil.getChar("Digit", locale));
	symbols.setExponentSeparator(
			SakaiLocaleServiceProviderUtil.getString("ExponentSeparator", locale));
	symbols.setGroupingSeparator(
			SakaiLocaleServiceProviderUtil.getChar("GroupingSeparator", locale));
	symbols.setInfinity(
			SakaiLocaleServiceProviderUtil.getString("Infinity", locale));
	symbols.setInternationalCurrencySymbol(
			SakaiLocaleServiceProviderUtil.getString("InternationalCurrencySymbol", locale));
	symbols.setCurrencySymbol(
			SakaiLocaleServiceProviderUtil.getString("CurrencySymbol", locale));
	symbols.setMinusSign(
			SakaiLocaleServiceProviderUtil.getChar("MinusSign", locale));
	symbols.setMonetaryDecimalSeparator(
			SakaiLocaleServiceProviderUtil.getChar("MonetaryDecimalSeparator", locale));
	symbols.setNaN(
			SakaiLocaleServiceProviderUtil.getString("NaN", locale));
	symbols.setPatternSeparator(
			SakaiLocaleServiceProviderUtil.getChar("PatternSeparator", locale));
	symbols.setPercent(
			SakaiLocaleServiceProviderUtil.getChar("Percent", locale));
	symbols.setPerMill(
			SakaiLocaleServiceProviderUtil.getChar("PerMill", locale));
	symbols.setZeroDigit(
			SakaiLocaleServiceProviderUtil.getChar("ZeroDigit", locale));

	return symbols;
}