Java Code Examples for java.text.NumberFormat#getMaximumFractionDigits()

The following examples show how to use java.text.NumberFormat#getMaximumFractionDigits() . 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: ParameterFormat.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Configures the number pattern to use for the given value. The main intent of this method is to ensure that
 * the map projection scale factor (a value close to 1) is formatted with a sufficient number of fraction digits.
 * A common default NumberFormat precision is 3 digits, which is not sufficient. For example the scale factor of
 * Transverse Mercator projections is 0.9996 (4 digits), and the scale factor of "NTF (Paris) / Lambert zone II"
 * projection is 0.99987742 (8 digits).
 *
 * @param  format  the format to configure.
 * @param  m       the absolute value (magnitude) of the value to write.
 */
private static void configure(final NumberFormat format, final double m) {
    if (format.getMaximumFractionDigits() <= 9) {
        /*
         * If the maximum fraction digits is higher than 9, then that value has not been set by this class.
         * Maybe the user overrides the createFormat(Class<?>) method in his own subclass, in which case we
         * will respect his wish and not set a lower value here.
         */
        final int n;
        if (m < 10) {
            n = 9;
        } else if (m < 1000) {  // No real use case for this threshold yet, but added for more progressive behavior.
            n = 6;
        } else {
            n = 3;
        }
        /*
         * The minimum fraction digits is usually 0. But if we find a higher value (for example because the
         * user overrides the createFormat(Class<?>) method), then we will respect user's wish and not set
         * a lower value.
         */
        if (n >= format.getMinimumFractionDigits()) {
            format.setMaximumFractionDigits(n);
        }
    }
}
 
Example 2
Source File: AbstractNumberValidator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Returns the <i>multiplier</i> of the <code>NumberFormat</code>.</p>
 *
 * @param format The <code>NumberFormat</code> to determine the
 *        multiplier of.
 * @return The multiplying factor for the format..
 */
protected int determineScale(NumberFormat format) {
    if (!isStrict()) {
        return -1;
    }
    if (!isAllowFractions() || format.isParseIntegerOnly()) {
        return 0;
    }
    int minimumFraction = format.getMinimumFractionDigits();
    int maximumFraction = format.getMaximumFractionDigits();
    if (minimumFraction != maximumFraction) {
        return -1;
    }
    int scale = minimumFraction;
    if (format instanceof DecimalFormat) {
        int multiplier = ((DecimalFormat)format).getMultiplier();
        if (multiplier == 100) { // CHECKSTYLE IGNORE MagicNumber
            scale += 2; // CHECKSTYLE IGNORE MagicNumber
        } else if (multiplier == 1000) { // CHECKSTYLE IGNORE MagicNumber
            scale += 3; // CHECKSTYLE IGNORE MagicNumber
        }
    } else if (formatType == PERCENT_FORMAT) {
        scale += 2; // CHECKSTYLE IGNORE MagicNumber
    }
    return scale;
}
 
Example 3
Source File: TieRoundingTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static void formatOutputTestObject(NumberFormat nf,
                                   Object someNumber,
                                   String tiePosition,
                                   String inputDigits,
                                   String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(someNumber);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Error formatting number value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println("Number self output representation: " + someNumber);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.print("Success. Number input :" + inputDigits);
        System.out.print(", rounding : " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", tie position : " + tiePosition);
        System.out.println(", expected : " + expectedOutput);
    }
}
 
Example 4
Source File: TieRoundingTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void formatOutputTestObject(NumberFormat nf,
                                   Object someNumber,
                                   String tiePosition,
                                   String inputDigits,
                                   String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(someNumber);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Failure : error formatting value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println("Number self output representation: " + someNumber);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.print("Success. Number input :" + inputDigits);
        System.out.print(", rounding : " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", tie position : " + tiePosition);
        System.out.println(", expected : " + expectedOutput);
    }
}
 
Example 5
Source File: TieRoundingTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void formatOutputTestObject(NumberFormat nf,
                                   Object someNumber,
                                   String tiePosition,
                                   String inputDigits,
                                   String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(someNumber);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Failure : error formatting value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println("Number self output representation: " + someNumber);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.print("Success. Number input :" + inputDigits);
        System.out.print(", rounding : " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", tie position : " + tiePosition);
        System.out.println(", expected : " + expectedOutput);
    }
}
 
Example 6
Source File: TieRoundingTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void formatOutputTestLong(NumberFormat nf,
                                 long longToTest,
                                 String tiePosition,
                                 String inputDigits,
                                 String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(longToTest);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Failure : error formatting value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.print("Success. Long input :" + inputDigits);
        System.out.print(", rounding : " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", tie position : " + tiePosition);
        System.out.println(", expected : " + expectedOutput);

    }
}
 
Example 7
Source File: TieRoundingTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static void formatOutputTestObject(NumberFormat nf,
                                   Object someNumber,
                                   String tiePosition,
                                   String inputDigits,
                                   String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(someNumber);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Failure : error formatting value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println("Number self output representation: " + someNumber);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.print("Success. Number input :" + inputDigits);
        System.out.print(", rounding : " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", tie position : " + tiePosition);
        System.out.println(", expected : " + expectedOutput);
    }
}
 
Example 8
Source File: LSCurrencyFormat.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
public cfData execute( cfSession _session, List<cfData> parameters )throws cfmRunTimeException{
   double number;
   String type;
   String returnString = "";
   NumberFormat numFormat = NumberFormat.getCurrencyInstance( _session.getLocale() );
   int localeMinDecDigits = numFormat.getMinimumFractionDigits();
   int localeMaxDecDigits = numFormat.getMaximumFractionDigits();
   
   if ( parameters.size() == 2 ){
     number	= getDoubleWithChecks( _session, parameters.get(1) );
     type		= parameters.get(0).getString();
   } else {
     number	= getDoubleWithChecks( _session, parameters.get(0) );
     type		= "local";
   }
     
   if( type.equalsIgnoreCase( "local" ) ){
     returnString = numFormat.format(number);
   }

   else if( type.equalsIgnoreCase( "none" ) ){
     numFormat = NumberFormat.getInstance( _session.getLocale() );
     numFormat.setMinimumFractionDigits( localeMinDecDigits );
     numFormat.setMaximumFractionDigits( localeMaxDecDigits );
  Localization.updateNoneCurrencyFormat( _session.getLocale(), numFormat );
     returnString = numFormat.format(number);
   }
     
   else if( type.equalsIgnoreCase( "international" ) ){
     numFormat = NumberFormat.getInstance( _session.getLocale() );
     numFormat.setMinimumFractionDigits( localeMinDecDigits );
     numFormat.setMaximumFractionDigits( localeMaxDecDigits );
     returnString = new DecimalFormatSymbols( _session.getLocale() ).getInternationalCurrencySymbol() + numFormat.format(number);
   }
   else
     throwException( _session,  " invalid  type: "+type+" in LSCurrencyFormat" );
   
   return new cfStringData( returnString );
}
 
Example 9
Source File: TieRoundingTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void formatOutputTestLong(NumberFormat nf,
                                 long longToTest,
                                 String tiePosition,
                                 String inputDigits,
                                 String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(longToTest);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Failure : error formatting value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.print("Success. Long input :" + inputDigits);
        System.out.print(", rounding : " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", tie position : " + tiePosition);
        System.out.println(", expected : " + expectedOutput);

    }
}
 
Example 10
Source File: TieRoundingTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void formatOutputTestObject(NumberFormat nf,
                                   Object someNumber,
                                   String tiePosition,
                                   String inputDigits,
                                   String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(someNumber);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Failure : error formatting value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println("Number self output representation: " + someNumber);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.print("Success. Number input :" + inputDigits);
        System.out.print(", rounding : " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", tie position : " + tiePosition);
        System.out.println(", expected : " + expectedOutput);
    }
}
 
Example 11
Source File: TieRoundingTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static void formatOutputTestObject(NumberFormat nf,
                                   Object someNumber,
                                   String tiePosition,
                                   String inputDigits,
                                   String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(someNumber);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Failure : error formatting value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println("Number self output representation: " + someNumber);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.print("Success. Number input :" + inputDigits);
        System.out.print(", rounding : " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", tie position : " + tiePosition);
        System.out.println(", expected : " + expectedOutput);
    }
}
 
Example 12
Source File: TieRoundingTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
static void formatOutputTestLong(NumberFormat nf,
                                 long longToTest,
                                 String tiePosition,
                                 String inputDigits,
                                 String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(longToTest);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Error formatting double value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.print("Success. Long input :" + inputDigits);
        System.out.print(", rounding : " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", tie position : " + tiePosition);
        System.out.println(", expected : " + expectedOutput);

    }
}
 
Example 13
Source File: TieRoundingTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void formatOutputTestLong(NumberFormat nf,
                                 long longToTest,
                                 String tiePosition,
                                 String inputDigits,
                                 String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(longToTest);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Failure : error formatting value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.print("Success. Long input :" + inputDigits);
        System.out.print(", rounding : " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", tie position : " + tiePosition);
        System.out.println(", expected : " + expectedOutput);

    }
}
 
Example 14
Source File: TieRoundingTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static void formatOutputTestLong(NumberFormat nf,
                                 long longToTest,
                                 String tiePosition,
                                 String inputDigits,
                                 String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(longToTest);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Failure : error formatting value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.print("Success. Long input :" + inputDigits);
        System.out.print(", rounding : " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", tie position : " + tiePosition);
        System.out.println(", expected : " + expectedOutput);

    }
}
 
Example 15
Source File: TieRoundingTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
static void formatOutputTestObject(NumberFormat nf,
                                   Object someNumber,
                                   String tiePosition,
                                   String inputDigits,
                                   String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(someNumber);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Error formatting number value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println("Number self output representation: " + someNumber);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.print("Success. Number input :" + inputDigits);
        System.out.print(", rounding : " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", tie position : " + tiePosition);
        System.out.println(", expected : " + expectedOutput);
    }
}
 
Example 16
Source File: TieRoundingTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void formatOutputTestLong(NumberFormat nf,
                                 long longToTest,
                                 String tiePosition,
                                 String inputDigits,
                                 String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(longToTest);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Failure : error formatting value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.print("Success. Long input :" + inputDigits);
        System.out.print(", rounding : " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", tie position : " + tiePosition);
        System.out.println(", expected : " + expectedOutput);

    }
}
 
Example 17
Source File: TieRoundingTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void formatOutputTestLong(NumberFormat nf,
                                 long longToTest,
                                 String tiePosition,
                                 String inputDigits,
                                 String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(longToTest);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Failure : error formatting value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.print("Success. Long input :" + inputDigits);
        System.out.print(", rounding : " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", tie position : " + tiePosition);
        System.out.println(", expected : " + expectedOutput);

    }
}
 
Example 18
Source File: TieRoundingTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
static void formatOutputTestDouble(NumberFormat nf,
                                   double doubleToTest,
                                   String tiePosition,
                                   String inputDigits,
                                   String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(doubleToTest);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Failure : error formatting value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println("BigDecimal output : " +
                           new BigDecimal(doubleToTest).toString());
        System.out.println("FloatingDecimal output : " + doubleToTest);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.println("\nSuccess for double value : " + doubleToTest + " :");
        System.out.println(" Input digits :" + inputDigits +
                           ", BigDecimal value : " +
                           new BigDecimal(doubleToTest).toString());
        System.out.print(" Rounding mode: " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", position : " + tiePosition + " tie");
        System.out.print(", result : " + result);
        System.out.println(", expected : " + expectedOutput);
    }
}
 
Example 19
Source File: TieRoundingTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static void formatOutputTestDouble(NumberFormat nf,
                                   double doubleToTest,
                                   String tiePosition,
                                   String inputDigits,
                                   String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(doubleToTest);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Failure : error formatting value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println("BigDecimal output : " +
                           new BigDecimal(doubleToTest).toString());
        System.out.println("FloatingDecimal output : " + doubleToTest);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.println("\nSuccess for double value : " + doubleToTest + " :");
        System.out.println(" Input digits :" + inputDigits +
                           ", BigDecimal value : " +
                           new BigDecimal(doubleToTest).toString());
        System.out.print(" Rounding mode: " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", position : " + tiePosition + " tie");
        System.out.print(", result : " + result);
        System.out.println(", expected : " + expectedOutput);
    }
}
 
Example 20
Source File: TieRoundingTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
static void formatOutputTestDouble(NumberFormat nf,
                                   double doubleToTest,
                                   String tiePosition,
                                   String inputDigits,
                                   String expectedOutput) {

    int mfd = nf.getMaximumFractionDigits();
    RoundingMode rm = nf.getRoundingMode();
    String result = nf.format(doubleToTest);

    if (!result.equals(expectedOutput)) {
        System.out.println();
        System.out.println("========================================");
        System.out.println("***Failure : error formatting value from string : " +
                           inputDigits);
        System.out.println("NumberFormat pattern is  : " +
                           ((DecimalFormat ) nf).toPattern());
        System.out.println("Maximum number of fractional digits : " + mfd);
        System.out.println("Fractional rounding digit : " + (mfd + 1));
        System.out.println("Position of value relative to tie : " + tiePosition);
        System.out.println("Rounding Mode : " + rm);
        System.out.println("BigDecimal output : " +
                           new BigDecimal(doubleToTest).toString());
        System.out.println("FloatingDecimal output : " + doubleToTest);
        System.out.println(
           "Error. Formatted result different from expected." +
           "\nExpected output is : \"" + expectedOutput + "\"" +
           "\nFormated output is : \"" + result + "\"");
        System.out.println("========================================");
        System.out.println();

        errorCounter++;
        allPassed = false;
    } else {
        testCounter++;
        System.out.println("\nSuccess for double value : " + doubleToTest + " :");
        System.out.println(" Input digits :" + inputDigits +
                           ", BigDecimal value : " +
                           new BigDecimal(doubleToTest).toString());
        System.out.print(" Rounding mode: " + rm);
        System.out.print(", fract digits : " + mfd);
        System.out.print(", position : " + tiePosition + " tie");
        System.out.print(", result : " + result);
        System.out.println(", expected : " + expectedOutput);
    }
}