2

I am trying to export to an excel sheet values using the correct decimal separator according to the SO configured decimal separator on regional settings. I tried using:

private static Locale tp = Locale.getDefault();
DecimalFormatSymbols dfs = new DecimalFormatSymbols(tp);
String sep = Character.toString(dfs.getDecimalSeparator());

But the dfs.getDecimalSeparator() always returns 'comma' even if I change in the regional settings from 'comma' to 'point'.

As far as I understood Locale.getDefault() returns the locale that was initially determined by the Java Virtual Machine (JVM) when it first loaded. That is, the JVM determines the default locale from the host environment. The host environment's locale is determined by the host operating system and the user preferences established on that system.

But let's say I don't want to get the Locale's decimal separator, but I want to get what's configured in the regional settings even thought it is not the locales, how do I do that?

C:\Users\admim>java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
Fabio Carvalho
  • 459
  • 4
  • 14
  • 1
    *"even if I change in the regional settings"* Where are you making that change? Note that Java has internal files mapping Locales to DecimalFormatSymbols. The symbols are *not* read from the "current" settings of the OS. – Andreas Sep 13 '16 at 18:58
  • what do you man by regional settings? – Nicolas Filotto Sep 13 '16 at 19:01
  • Hi, I am changing the decimal separator on "Control Panel -> Region and Language" than clicking Additional Settings. That's what i called Regional Settings. – Fabio Carvalho Sep 13 '16 at 19:05
  • Andreas, how do I read the current settings of the OS ? – Fabio Carvalho Sep 13 '16 at 19:06
  • I closed as duplicate of "[How can I set date and time formatting in Java that respects the user's OS settings](http://stackoverflow.com/q/6711925/5221149)" even though that's about date format and your question is about number format, but it's really the same issue. In short: **Java doesn't support it.** You have to read the Windows registry yourself to get the "Region and Language" values, and then interpret them correctly. – Andreas Sep 13 '16 at 21:00
  • Reopened, since new search found a better answer: [Get number format from OS](http://stackoverflow.com/a/24625228/5221149). See official notice: [Internationalization Enhancements in JDK 8](https://docs.oracle.com/javase/8/docs/technotes/guides/intl/enhancements.8.html#cldr) – Andreas Sep 13 '16 at 21:04
  • Thanks Andreas for your search. It is exactly what I need, but still....it didn't work. I tried using: **String localeProvidersList = System.getProperty("java.locale.providers", "HOST,JRE,SPI");** It seems I am still looking up for the default JRE and SPI. – Fabio Carvalho Sep 15 '16 at 13:13
  • Is there another way to configure the **java.locale.providers** system property that I may be missing? In the link you suggested me, it says "Running my example above with **-Djava.locale.providers=HOST,JRE,SPI** ...". Is this some kind of argument? Or the solution is simply to add to my code the System.getProperty statement? Sorry for my lack of knowledge on that, but it's been a while I don't program with Java and it's a big system. – Fabio Carvalho Sep 15 '16 at 13:28

0 Answers0