Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8039915

Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5

XMLWordPrintable

    • b36
    • generic
    • generic
    • Verified

        FULL PRODUCT VERSION :
        java version "1.8.0"
        Java(TM) SE Runtime Environment (build 1.8.0-b132)
        Java HotSpot(TM) Server VM (build 25.0-b70, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        Linux paris 2.6.32-220.4.1.el6.i686 #1 SMP Mon Feb 6 16:10:45 CET 2012 i686 i686 i386 GNU/Linux


        A DESCRIPTION OF THE PROBLEM :
        Formating 0.950000550000 to a six fraction digits works properly, I get "0.950001".
        Formating 0.950000600000 to a six fraction digits works wrong, I get "0.95" instead of "0.950001".


        REGRESSION. Last worked in version 7u51


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        @Test
        public void test_roundingOfDoubleValues() {
          NumberFormat format = DecimalFormat.getInstance( Locale.US );
          format.setGroupingUsed( false );
          format.setMaximumFractionDigits( 6 );
          format.setRoundingMode( RoundingMode.HALF_UP );
          String val95000055 = format.format( 0.950000550000 );
          assertEquals( "0.950001", val95000055 ); // this is okay
          String val95000060 = format.format( 0.950000600000 );
          assertEquals( "0.950001", val95000060 ); // this provides an error
        }

        ---------- END SOURCE ----------

              olagneau Olivier Lagneau (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: