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();
}
}
}
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();
}
}
}
- duplicates
-
JDK-4510618 [Fmt-Nu] French thousands separator is non-breaking space
-
- Closed
-