FULL PRODUCT VERSION :
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
DecimalFormat will return non-floating-point objects (e.g. Long) for patterns containing a minimum number fraction digits greater than zero (getMinimumFractionDigits), when parsing whole numbers. The behavior I would expect would be to return a Double/Float of the given whole number.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run test case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect the type of the returned object to be a floating-point type like Float or Double. Instead it returns a Long.
ACTUAL -
The object returned is of type 'Long'
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.text.DecimalFormat;
public class TestDecimalFormat {
public static void main(String[] args) throws Exception {
// provide a decimal format with a mandatory fraction digit
DecimalFormat format = new DecimalFormat("#,##0.0#");
// sanity check here
System.out.println("isParseIntegerOnly? " + format.isParseIntegerOnly());
// if getMinimumFractionDigits is non-zero, I would expect the object returned
// to be a floating-point type, i.e. Float or Double
System.out.println("getMinimumFractionDigits()? " + format.getMinimumFractionDigits());
// this is a whole number, however the fraction is mandatory in the above pattern
// so we would expect a floating-point type to be returned
String number = "123.0";
Object o = format.parseObject(number);
System.out.println("Parsed value: " + o);
System.out.println("Parsed value class (expect floating point): " + o.getClass());
}
}
---------- END SOURCE ----------
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
DecimalFormat will return non-floating-point objects (e.g. Long) for patterns containing a minimum number fraction digits greater than zero (getMinimumFractionDigits), when parsing whole numbers. The behavior I would expect would be to return a Double/Float of the given whole number.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run test case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect the type of the returned object to be a floating-point type like Float or Double. Instead it returns a Long.
ACTUAL -
The object returned is of type 'Long'
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.text.DecimalFormat;
public class TestDecimalFormat {
public static void main(String[] args) throws Exception {
// provide a decimal format with a mandatory fraction digit
DecimalFormat format = new DecimalFormat("#,##0.0#");
// sanity check here
System.out.println("isParseIntegerOnly? " + format.isParseIntegerOnly());
// if getMinimumFractionDigits is non-zero, I would expect the object returned
// to be a floating-point type, i.e. Float or Double
System.out.println("getMinimumFractionDigits()? " + format.getMinimumFractionDigits());
// this is a whole number, however the fraction is mandatory in the above pattern
// so we would expect a floating-point type to be returned
String number = "123.0";
Object o = format.parseObject(number);
System.out.println("Parsed value: " + o);
System.out.println("Parsed value class (expect floating point): " + o.getClass());
}
}
---------- END SOURCE ----------
- relates to
-
JDK-8352755 Misconceptions about j.text.DecimalFormat digits during parsing
-
- Open
-