I try to get a Double-Value of a Number which is formatted in French style. So the Text 1 003,25 should stored as value (1003.25).
public class NumberFormatTest {
public static void main(String[] args) throws ParseException {
String db = "1003.25";
String manualFRA = "1 003,25";
double numberDB = Double.parseDouble(db);
String ger = NumberFormat.getInstance(Locale.GERMAN).format(numberDB);
String fra = NumberFormat.getInstance(Locale.FRENCH).format(numberDB);
String eng = NumberFormat.getInstance(Locale.ENGLISH).format(numberDB);
double gerD = NumberFormat.getNumberInstance(Locale.GERMAN).parse(ger).doubleValue();
double fraD = NumberFormat.getNumberInstance(Locale.FRENCH).parse(fra).doubleValue();
double mfraD = NumberFormat.getNumberInstance(Locale.FRENCH).parse(manualFRA).doubleValue();
double engD = NumberFormat.getNumberInstance(Locale.ENGLISH).parse(eng).doubleValue();
System.out.println("From database: " + db);
System.out.println("\tGerman: " + ger);
System.out.println("\tFrench: " + fra);
System.out.println("\tEnglish: " + eng);
System.out.println("\nTo Database: ");
System.out.println("\tfrom German: "+ gerD);
System.out.println("\tfrom French: "+ fraD);
System.out.println("\tfrom manual French: "+ mfraD);
System.out.println("\tfrom Englisch: "+ engD);
}
}
From database: 1003.25
German: 1.003,25
French: 1 003,25
English: 1,003.25
To Database:
from German: 1003.25
from French: 1003.25
from manual French: 1.0
from Englisch: 1003.25
Does anybody has an idea, why the manual French value is 1.0 and not 1003.25? How can I solve it? In the real program the value comes as String from an TextField.
Thanks in advance for your help!