JDK-6318800 : parse() method of NumberFormat does not parse for French Locale
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 5.0u4
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-09-01
  • Updated: 2011-02-16
  • Resolved: 2005-09-01
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
     I am using the class NumberFormat to parse strings for French Locale, that is, I get a NumberFormat object with locale set to French. When the string "345 888,246" is parsed to a number, it returns 345 instead of 345888.246.  That is, the method parse() is not taking the entire string as an argument.
   I have another class ReverseNumberFormat, which formats 345888.246 to French locale string. After that, it parses the French locale string back to the actual number. It works properly, that is, it gives the output 345888.246. Can anyone help me. Thanks in advance.
   I can use the character ' \u00a0' in place of space, but that is not acceptable for me as I have to use this for every space. It will make my code not understandable.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
import java.text.NumberFormat;
import java.util.Locale;
class TestNumberFormat
{
	public static void main(String args[])
	{
		 NumberFormat  numberFormat=NumberFormat.getNumberInstance(Locale.FRENCH);
		 try
		 {
			 Number n=numberFormat.parse("345 888,246");
			 System.out.println(n);
		 }
		 catch(Exception e)
		 {
			 System.out.println("Exception "+e);
		 }
	    }
  }


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
345888.246

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
import java.text.NumberFormat;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.ParseException;
import java.util.Locale;
class NewTestNumberFormat
{
	public static void main(String args[])
	{
		 NumberFormat numberFormat=NumberFormat.getNumberInstance(Locale.FRENCH);
		 DecimalFormat df = (DecimalFormat) numberFormat;
		 DecimalFormatSymbols symbols = df.getDecimalFormatSymbols();
		 symbols.setGroupingSeparator(' ');
		 df.setDecimalFormatSymbols(symbols);
		 try {
			
			System.out.println(df.parse("345 888,246"));
		} catch (ParseException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	    }
     }
}

Comments
EVALUATION I close this bug as a duplicate of 4510618. Under the curernt spec of DecimalFormat, using the follow code is a correct way to use ' '. DecimalFormatSymbols symbols = df.getDecimalFormatSymbols(); symbols.setGroupingSeparator(' '); df.setDecimalFormatSymbols(symbols); *** (#1 of 1): [ UNSAVED ] ###@###.###
01-09-2005