I am making a Java application localized in French. I used some JSpinner
s that accept only a float.
The problem is that the decimal point (the separator between integer part and decimal part) in float numbers is represented by a comma ( ,
). This behavior make a number like 12.34
invalid and the JSpinner
reject it, but If I type 12,34
it will be accepted.
How can I force a JSpinner
to use a dot ( .
) as the decimal point and not the comma ?
The main
method begin like this :
public static void main(String args[]) {
Locale.setDefault(Locale.FRENCH); // Set French as the application language
/* ... */
}
I found the solution. When you use the method Locale.setDefault(Locale)
it sets the default locale for display and also for formatting , but in my case, I need only to display my user interfaces in French. For that, I have to use also the second overload of the method : setDefault(Locale.Category, Locale)
, where the first parameter indicate if I want to use the locale for displaying user interfaces or for formatting date, numbers or curencies. The main method now is like this :
Locale.setDefault(Locale.FRENCH); // Display the user interfaces in French
Locale.setDefault(Locale.Category.FORMAT, Locale.ENGLISH); // But the formatting in English
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.